Link to the official competition
The objective of the competition
Create the best-performing solution for a People CRUD application, considering some specific constraints.
Main criteria: The solution with the most records created wins
Components
2 APIs instances
1 Load balancer
1 DB of their choice (MongoDB, Postgres, MySQL)
Constraints
CPU: 1,5 units
Memory: 3GB
Purpose of this article
Share strategies used in the solutions and what I have learned
I have chosen arbitrarily not the competition's winner, but one node and go solutions.
The reason was simply that I know Node and would like to see how other people would implement it, and I wanted to learn more about Go Lang.
NodeJS Approach
records: 2835
Observations
He decided to use NestJS which I haven't used, but it is interesting to see how well structured the project became with it.
NestJS is a “Strongly opinionated framework” for building node applications.
It is inspired a lot by Angular (SOLID, OOP, FP…)
Strategies used for this solution
Caching: redis
Redis was chosen because it is an in-memory database, that improves reading performance
bull is a distributed queue library to be able to reach concurrency in node
in this solution, it was used to do concurrent calls to databases (redis and MongoDB)
Database: Redis + MongoDB (NoSQL)
GoLang Approach (top 2 solution)
records: 44270
framework - NestJS
strategies
caching
GoRoutine + JOBs
DB: PostgreSQL
Takeaways
Even though Go's database had 30% more CPU and its API had 85% more CPU than Node's, Go's created 15x more records considering the competition's constraints
That shows how GoRoutines really take more advantage of processing data on the CPU with multiple threads compared to Node's architecture
Clean Architecture and SOLID were interestingly applied in both projects
It was interesting to learn:
How to read GoLang, and see the power of GoRoutines
NestJS (although I feel more inclined to express in smaller projects)
Seeing different projects broadens your view about how to tackle a problem, in a language-agnostic way
Resources to dive deeper
Competition Repository: rinha-de-backend-2023-q3
Go Concurrency Explained: Go Routines & Channels
PostgreSQL outperforms MongoDB in almost,will never go wrong withPostgreSQL