Ankit Sinha

Field note / 04

Row locks, cursor outboxes, and Redis rebuilds

Caches and job queues make an economy fast, but they should never own the truth. Serialize every mutation in PostgreSQL, resume large payouts by cursor, and treat Redis purely as a rebuildable read index.

Nov 2026 · 3 min read · from IdleForge

Serialize the balance, persist the key #

Mobile retries, double-taps, and overlapping offline-earnings requests break naive balance math immediately. In-memory de-duplication masks the bug only on a single node.

command (idempotency_key)
  └─ purchase_commands check ─▶ SELECT ... FOR UPDATE (player row)
                                   └─ balance + ledger_entries + event_outbox (1 tx)
                                         └─ BullMQ drains via last_player_id cursor

Resume by cursor, fail closed on cache #

Speed layers stay safe only when you can drop them cleanly and reconstruct them deterministically from SQL.