Open source project

Flash Sale Platform

A flash sale demo that uses one Redis Lua script to stop overselling when many people click Reserve at once.

  • TypeScript
  • Fastify
  • Redis
  • Lua
  • SQS
  • DynamoDB
  • Docker

I built this demo to show how Redis can handle a flash sale, where everyone clicks at once. The shop has limited stock, and the sale opens at a set time.

A reservation is a single Lua script in Redis. It checks the customer and the stock and takes the item in one step, so two people can’t get the last one. A unique request key makes sure each customer reserves only one item. The API answers straight away, and a worker saves the reservation from an SQS queue to DynamoDB. A hold that isn’t checked out within three minutes expires, and a sweeper puts the item back on sale.

It runs with one docker compose up, and the repository has diagrams of the local setup and a production design on AWS.

View the repository on GitHub

Loading the terminal…