pt-BR
: Este repositório consiste em apresentar o código da minha participação na Rinha de Backend 2024 Q1 origanizada pelo @zanfranceschi. Nesta edição o tema foi o gerenciamento de concorrência e tendo como tópico transações bancárias seguindo alguns critérios (exemplo: 1.5
de CPU e 550Mb
de RAM para toda a infraestrutura). Você consegue saber mais sobre os detalhes do projeto diretamente no Repositório da Rinha, sendo que neste link você encontra o meu fork.
en-US
: This repository shows the code from my participation in the Rinha de Backend 2024 Q1 organized by @zanfranceschi. In this edition the topic was concurrency management on banking transactions following some criterias (e.g.: 1.5
cpu and 550Mb
ram for all the infrastructure). You can find out more about on Rinha de Backend repository, where in this link you will find my fork.
✔️ Rinha de Backend means something like Backend Fight.
💻 Lessons Learnt:
- Windows dynamic ports can block the Load Testing after some time;
- Handle concurrency in Postgres with
pg_advisory_xact_lock
vsFOR UPDATE
; ConnectionPool
configurations forPostgres
, super flexible;NpgsqlDataSource
singleton instance can be helpful in this kind of scenario;Nginx
as Load Balancer is really good and get the job done;- Optimizations in
csproj
for compilations includingNative AOT
in .NET 8 and speed up the process and the runtime; - Linux Ubuntu setup for .NET (I used to use just Windows);
Build the docker image for the project and up all the dependencies on the docker-compose.yml
including Postgres
database and Nginx
load balancer including all its configurations.
sh up.sh
After the load balancer will be listening on 9999
port, and you can request to it as an example:
GET http://localhost:9999/clientes/1/extrato
or
POST http://localhost:9999/clientes/1/transacoes
using the request body:
{
"valor": 1000,
"tipo" : "c",
"descricao" : "descricao"
}
Finally, you can down all the resources and destroy the container image by running:
sh down.sh
Once I was developing this project a Load Test using Gatling ran in order to evaluate the infrastructure. You can check the results on the image bellow:
Thank you.