Software Engineer and Student
Last updated: August 2025
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.
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.