Hack Reactor System Design Capstone Project, which involved scaling the Node.js RESTful API to handle x50 more traffic and reducing p90 latency to ~70ms (-95%). Developed NGINX load-balancer, optimized the PostgreSQL database, and preformed load-testing with K6 and Loader.io.
Situation: Refactoring a Node.js RESTful API deployed on AWS EC2, serving retail product data from a PostgreSQL database.
Task: Optimize and scale the API to handle production level traffic with low latency and <1% error rate. This backend was crucial to have ready for the next project, which was the frontend serving this data. It was a challenge without using a Kubernetes cluster or database sharding.
Action: Dockerized the API for horizontal scaling with the NGINX proxy service. Used the dynamic least connection algorithm for load balancing to distribute traffic. Optimized the Node.js app with caching, refactoring database queries, and other minor code improvements. Identified and resolved system bottlenecks with load testing using K6 and Loader.io.
Result: Achieved traffic from <10 RPS to reliable 700 RPS with 70 ms average latency and <1% error rate. Avoided breaking changes with testing and continuous integration, decreasing the stress testing cycle length to allow quick iteration of the system..
- Throughput: 100 RPS
- Latency: 2000 ms
- Error rate: <1% rate
- Throughput: ~700 RPS (Max 5000 RPS)
- Latency: ~70 ms
- Error rate: <1% rate
# [optional] Run the local postgres database
$ cd postgres_db
$ docker-compose up -d --build
# Start up the Node/Express server
$ cd server/app
$ npm install
$ cp .env.sample .env
# Update the DATABASE_URL environment variable
EXAMPLE_URL=postgresql://<username>:<password><host>:5432/<database>See ATELIER_API_DOCS.md to view the endpoint schema
Check out the Trello Scrum Board used to plan user stories and create tasks during development.
Read about learning/challenges of this project:
