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
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 defences | Without defences | |
|---|---|---|
| Seats sold | 1,200 | 777 |
| People who got seats | 619 | 415 |
| Most seats held by bots at once | 148 | 423 |
| Seats never sold | 0 | 423 |
| Seats sold twice | 0 | 0 |
Show the technical side
One buyer, step by step
- Take a number in the same waiting room as the flash sale (POST /api/antre). The counter calls 30 people a second.
- 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.
- 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.
- 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.
- 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 key | Holds |
|---|---|
ks:kursi | hash of seat number to holder and deadline, or order id |
ks:pegang | one active hold per identity: deadline and seat list |
ks:tahan | sorted set of identities by deadline, read by the sweeper |
ks:hukum | how often each identity let a hold lapse unpaid |
The defences and where they come from
| Rule | With | Without | Basis |
|---|---|---|---|
| Hold time | 30 s | 30 s | Lab runs 20 times faster; vendors use 5 to 20 minutes (TIX ID 7, BookMyShow 5 to 10, Loket 15) |
| Seats per hold | 4 | 10 | Coldplay Jakarta, Loket, GOERS, BookMyShow ID: 4 per transaction, tied to an identity |
| Picking again extends | no | yes | Delta fines repeated book-and-cancel to extend the deadline (churning) |
| Blocked after expiry no. | 2 | never | Our 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
| Measured | Field | With | Without |
|---|---|---|---|
| Seats sold twice | kursi_ganda | no | no |
| Sold according to Redis | terjual | 1,200 | 777 |
| kursi_terjual rows in Postgres | kursi_di_postgres | 1,200 | 777 |
| Sold on the replayed map | terjual_di_peta_akhir | 1,200 | 777 |
| Ledger balanced, seats x Rp850,000 | ledger_benar | yes | yes |
| Seats released | kursi_kembali | 335 | 553 |
| Latest release after the deadline (ms) | kembali_telat_ms_maks | 129 | 100 |
| Holds refused for a clash | tahan_bentrok | 14,465 | 8,107 |
| Holds or queueing refused by a block | tahan_dihukum + antre_dihukum | 9 | 0 |
| 5xx errors | galat_5xx | 0 | 0 |
| Worst per-second hold and pay p95 (ms) | latensi_beli_p95_maks | 276 | 61 |
| Laptop CPU before / after (%) | cpu_host_* | 81 / 71 | 50 / 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.