← Projects

CityScout

A flash-sale ordering backend that sustains 5,000 TPS on one 8-vCPU VM, with Redis Lua stock reservation, Kafka async order writes, and an explicit recovery for every failure path.

Source on GitHub ↗

Java 17 · Spring Boot · Redis · Kafka · MySQL · Docker

CityScout started from the hm-dianping Spring Boot course project. The part I rebuilt is the seckill path, where the hard problem isn’t speed but never selling a voucher twice, and never losing one when a step fails halfway.

On a single 8-vCPU VM the path sustains 5,000 TPS, and moving order writes off the request path to Kafka cut latency by 40%.

A request runs one Lua script that checks stock and the per-user limit, reserves, and writes a pending record, then returns the order id before Kafka confirms. The consumer writes MySQL, and afterCommit clears pending.

A concurrency script fires 200 users at 100 units of stock and checks that every count reconciles: 100 orders, no user with two, Redis and MySQL in agreement. Next I’d add metrics for consumer lag and DLT volume.