Code Monkey home page Code Monkey logo

fabacus's Introduction

Event Seat Booking

The following service supporting a busy online reservation system using NodeJS, Redis and Docker. Locking has been implemented for concurrent attempts to hold seats due to this busyness. Events have been modeled as collections of seats and are decoupled from these locks should a move to a database (SQL or noSQL) more suitable be required.

API

The following routes all require an x-user-id to be sent along with the requests. In practise, some authorisation & authentication controls would be needed here.

create event POST /events

Accepts a JSON body, NUM_SEATS must be an integer between 10 & 1000.

curl --location 'localhost:3000/events' \
--header 'x-user-id: <USER_ID>' \
--header 'Content-Type: application/json' \
--data '{
    "numSeats": <NUM_SEATS>
}'

list seats for event GET /events/<EVENT_ID>

For a given event list free seats, not held or reserved.

curl --location 'localhost:3000/events/8f1cbe5c-9e21-42f4-979a-ac3692b608c1/seats' \
--header 'x-user-id: <USER_ID>'

hold a seat PATCH /events/<EVENT_ID>/seats/<SEAT_ID>/hold

Hold a seat prior to reservation for a configurable duration.
If the seat is already held by that user, it will refresh. The maximum number of seats a user can hold is configurable, defaulting to 3. This includes held seats that are then reserved.

curl --location --request PATCH 'localhost:3000/events/<EVENT_ID>/seats/<SEAT_ID>/hold' \
--header 'x-user-id: foo'

reserve a seat PATCH /events/<EVENT_ID>/seats/<SEAT_ID>/reserve

reserve a seat that the user currently holds

curl --location --request PATCH 'localhost:3000/events/<EVENT_ID>/seats/<SEAT_ID>/reserve' \
--header 'x-user-id: foo'

running the application

build

npm i && npm run build && docker compose build

starting the application

docker compose up

tests

npm t

linting

npm run lint

fix linting

npm run lint -- --fix

environment variables

all can be set in docker-compose.yml with defaults in src/config.ts

PORT

port the service will listen on

REDIS_URL

address at which redis can be reached

LOCK_EXPIRY_MS

time window in which unresolved locks on multiple users attempting to hold the same seat will clear. Will only be relevant if the app is killed during an attempt to hold a seat

HOLD_EXPIRY_MS

maximum duration between a user holding a seat and finalising the reservation

MAX_EVENT_SEATS_PER_USER

maximum number of seats assignable to a user. Includes holds and reservations

fabacus's People

Watchers

Matthew Butler avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.