Introduction to Rinha de Backend - 2024/Q1
The Rinha de Backend event is an innovative challenge designed with the primary goal of sharing knowledge in a competitive yet educational format. As the second edition of this stimulating event, participants are encouraged to submit their solutions by March 10, 2024, 11:59:59 PM. The outcomes will be presented during a live session on March 14, 2024, at 7:00 PM on YouTube.
What is the Challenge About?
The theme for this edition focuses on concurrency control with a particular emphasis on managing credits and debits, whimsically referred to as "crébitos." This theme was inspired by the insightful exchanges of @lucascs and @kmyokoyama on Twitter. Participants will engage in developing a robust API to handle transactions effectively while adhering to specific rules to ensure consistency and reliability.
Participation Requirements
Participants are required to build an HTTP API featuring two main endpoints:
Transactions Endpoint
-
Request:
POST /clientes/[id]/transacoes
{ "valor": 1000, "tipo": "c", "descricao": "descricao" }
[id]
represents the customer's identifier and should be an integer.valor
is an integer representing cents (for example, 1000 cents is equivalent to R$ 10).tipo
is eitherc
for credit ord
for debit.descricao
is a textual description with a length of 1 to 10 characters.
-
Response:
The response for a successful transaction should return HTTP 200 with a JSON body containing the customer's limit and the new balance. Transactions must not allow a debit that exceeds the customer's limit.
Statement Endpoint
-
Request:
GET /clientes/[id]/extrato
-
Response:
This endpoint provides the total balance, statement date, and up to the last 10 transactions, sorted by date and time.
Key Constraints and Rules
- Debit transactions cannot reduce the balance below the available limit.
- Invalid requests or those leading to inconsistency must return HTTP 422, while non-existent customer IDs should return HTTP 404.
- A few initial clients are pre-registered for testing purposes:
- IDs range from 1 to 5 with specified limits and initial balances.
- A test exists to ensure ID 6 is non-existent.
Submission Guidelines
Participants need to submit their projects using a containerized approach (Docker and docker-compose) that includes an API and related services. The detailed submission should be structured with a pull request incorporating a directory of files such as:
docker-compose.yml
defining the services.README.md
containing participant details, technologies used, and public access to the source code.
Submissions should observe CPU and memory restrictions, not exceeding 1.5 CPU units and 550MB in total.
Architecture and Resource Constraints
A minimum API architecture requires:
- A load balancer for traffic distribution using round-robin algorithm listening on port 9999.
- Two web server instances serving HTTP requests.
- A database of choice, disallowing in-memory focused databases like Redis.
Participants are encouraged to optimize their solutions per the above constraints for efficient resource use and performance.
Testing
Performance tests will be conducted using the Gatling tool to ensure robustness and efficiency. Participants can execute tests to optimize their APIs, and various scenarios can be explored to tweak performance.
Conclusion
The Rinha de Backend event is more than just a challenge; it’s a comprehensive exercise to refine skills in backend development, focusing on concurrency, performance, and resilience. Whether participating solo or in a group, this event promises an enriching experience in practical problem-solving and innovation.