A solution to the system design problem of a fair, scalable queue and waiting list service, similar those seen with popular events retailers such as Ticketmaster. Written in Go.
The design of the system is documented in the system doc. The server(s) issue JWTs to users designating their queue position, tracking the number of issued tokens in Redis. A sliding window algorithm is used to determine, in batches, which tickets are active, and which are still waiting (or expired), sliding at a regular interval.
The system requires a Redis instance to be accessible. You can spin one up with the docker-compose config:
docker compose upYou can then run the Go app on bare metal with:
go run ./cmd/serverYou will need various environment variables set, listed below:
REDIS_ADDR # Full address of Redis instance (default: localhost:6379)
PORT # Port for the HTTP server to run on
JWT_SECRET # Secret used to sign JWTs
WINDOW_SIZE # Size of active ticket window(s)
WINDOW_INTERVAL # How often to slide window to next batch (in seconds)
ACTIVE_WINDOW_COUNT # How many windows (counted backwards from current) considered activeYou should then be able to hit the server on the port specified with a HTTP client. For example, with HTTPie:
http POST localhost:{port}/join
http GET localhost:{port}/status "Authorization: Bearer {token}"The repo also has some default Kubernetes configuration, that can be used for running the system, by default with 3 server replicas. You can find this config in the k8s folder, and documentation on it and how to run locally (with a minikube cluster) in the k8s docs. You can apply the k8s folder with the following:
kubectl apply -f k8s