Kanishk Sachdev

Software Engineer and Student

Now

Last updated: August 2025

Fast inventory reads without expensive sums

inventoryperformance

Our inventory tools power events with thousands of items across locations (HackPSU, THON). Summing live transactions on the read path was fine… until it wasn’t. We moved to denormalized quantities maintained on writes. Reads are now sub‑second and predictable under load.

// Maintain a denormalized quantity on write
type Tx = { itemId: string; delta: number; reason: 'checkin' | 'return' | 'adjustment' }

async function applyTransaction(db: DB, tx: Tx) {
  await db.transaction(async (trx) => {
    // 1) Record the transaction
    await trx.insert('inventory_transactions', {
      item_id: tx.itemId,
      delta: tx.delta,
      reason: tx.reason,
      created_at: new Date(),
    })

    // 2) Update the cached quantity atomically
    await trx.exec(
      'update inventory_items set quantity_cached = quantity_cached + ? where id = ?',
      [tx.delta, tx.itemId],
    )
  })
}

// Read path: no joins, no sums
async function getItem(db: DB, itemId: string) {
  return db.one('select id, name, quantity_cached from inventory_items where id = ?', [itemId])
}

Trade‑off: slightly more complexity on writes; big win on p95 reads during peak check‑in.

Auth that spans subdomains

authnext.js

We run multiple apps under the same org (dashboard, check‑in, sponsors). The goal was one login, everywhere. We settled on Firebase for identity and signed, domain‑wide session cookies for app hops.

// Pseudo: set a session cookie valid across subdomains
import { cookies } from 'next/headers'

function setSessionCookie(token: string) {
  cookies().set('session', token, {
    httpOnly: true,
    secure: true,
    sameSite: 'lax',
    domain: '.hackpsu.org', // works for app.hackpsu.org, sponsor.hackpsu.org, etc.
    path: '/',
    maxAge: 60 * 60 * 24 * 7,
  })
}

Constraints: minimal infra, student team ramp‑up friendly, works on Vercel. Trade‑off: cookie invalidation windows vs. simplicity.

What shipped recently

  • Inventory: denormalized read path and reconciliation job for drift.
  • Auth: domain‑wide sessions across HackPSU apps with smoother handoffs.
  • Finance: auto‑generated PDFs and email workflows for reimbursements.
  • Check‑in: faster QR/BLE flows and clearer failure states for volunteers.

Small experiments

  • N‑body gravity and boids with interactive controls.
  • Cloth tearing and sand cellular automata.
  • Rust map renderer weekend project — parallel parsing and tile rendering.

What’s next

  • Inventory: better audit trails and faster search across locations.
  • Sponsor dashboard analytics and smoother file handoffs.
  • POST terminal refinements for returns and invoice flows.