Back to System Design Lab

One seat, one person

A hall of 1,200 numbered seats. Thousands of people pick in the same second, and 60 bots hold seats they never pay for. This is a load test on a laptop, played back second by second.

Rules at the counter

Second0
Sold0
Held by people0
Held by bots0
Released0

On the map

  • Free
  • Held by a person
  • Held by a bot
  • Sold
  • Just released

Before the counter opens

60 bots queued before the counter opened, so they are called first. Real people are only starting to arrive.

Two recordings, same load

With defencesWithout defences
Seats sold1,200777
People who got seats619415
Most seats held by bots at once148423
Seats never sold0423
Seats sold twice00
Show the technical side

One buyer, step by step

  1. Take a number in the same waiting room as the flash sale (POST /api/antre). The counter calls 30 people a second.
  2. Whoever is called has 60 seconds to pick. The map (GET /api/kursi) is an in-memory copy in the API, refreshed every 300 ms, so hundreds of people opening it in the same second do not each read 1,200 seats from Redis.
  3. POST /api/kursi/tahan runs one Lua script: every requested seat must be free, or its hold must be past its deadline. If one seat clashes, nothing is held, and the 409 names the clashing seats.
  4. POST /api/kursi/bayar (with an Idempotency-Key) turns the hold into a sale, lowers the stock and writes the order to a Redis Stream, in the same atomic step.
  5. A worker writes the order to Postgres, one row per seat in kursi_terjual with the seat number as primary key, and books seats x Rp850,000 in the ledger.

Why expiry is checked inside the script

A store's own TTL cannot be the referee: Redis deletes expired keys on access or by random sampling, without telling the app, and DynamoDB can be days late. So every hold and pay script checks the deadline itself. A sweeper every 100 ms only tidies the map and records strikes. If the sweeper dies, no seat sells twice; only the map goes stale, and a test proves this with no sweeper running.

Redis keyHolds
ks:kursihash of seat number to holder and deadline, or order id
ks:pegangone active hold per identity: deadline and seat list
ks:tahansorted set of identities by deadline, read by the sweeper
ks:hukumhow often each identity let a hold lapse unpaid

The defences and where they come from

RuleWithWithoutBasis
Hold time30 s30 sLab runs 20 times faster; vendors use 5 to 20 minutes (TIX ID 7, BookMyShow 5 to 10, Loket 15)
Seats per hold410Coldplay Jakarta, Loket, GOERS, BookMyShow ID: 4 per transaction, tied to an identity
Picking again extendsnoyesDelta fines repeated book-and-cancel to extend the deadline (churning)
Blocked after expiry no.2neverOur addition, from airline practice and tixCraft account locks. Not found at any Indonesian vendor. The cost: an honest person who hesitates twice is blocked too.

Evidence from the two recordings

MeasuredFieldWithWithout
Seats sold twicekursi_gandanono
Sold according to Redisterjual1,200777
kursi_terjual rows in Postgreskursi_di_postgres1,200777
Sold on the replayed mapterjual_di_peta_akhir1,200777
Ledger balanced, seats x Rp850,000ledger_benaryesyes
Seats releasedkursi_kembali335553
Latest release after the deadline (ms)kembali_telat_ms_maks129100
Holds refused for a clashtahan_bentrok14,4658,107
Holds or queueing refused by a blocktahan_dihukum + antre_dihukum90
5xx errorsgalat_5xx00
Worst per-second hold and pay p95 (ms)latensi_beli_p95_maks27661
Laptop CPU before / after (%)cpu_host_*81 / 7150 / 100

Recorded 23 November 2026 with k6: arrivals rising to 150 buyers per second, 60 bot identities, API capped at 1 vCPU.

What the test does not show

  • One laptop, one Redis instance. The laptop was also busy with other work, so latency figures are samples; correctness figures (double sales, ledger) are not affected.
  • Bots and people are told apart by the identity k6 gives them. The server does not detect bots; it only enforces per-identity rules.
  • One bot, one identity. A bot rotating thousands of identities slips past per-identity limits; stopping it needs account checks or device signals, which belong to the next bot experiment.
  • Payment settles at once. The payment provider flow (payment experiment) is not wired to seats.
  • The simulator copies the rules and the k6 buyers' behaviour, without CPU or latency. With the test settings, seats sold at the end stay within 10% of the recordings. Mid-sale with defences, the simulated bots hang on longer: up to 11% of the map.