Skip to content

HarrisonTCodes/session-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Session Queue

Go Report Card Go Version CI Conventional Commits License: MIT

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.

Design

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.

Run Locally

The system requires a Redis instance to be accessible. You can spin one up with the docker-compose config:

docker compose up

You can then run the Go app on bare metal with:

go run ./cmd/server

You 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 active

You 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

About

A scalable HTTP service for handling high-traffic user queueing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published