Skip to content

2024 - The proposed of Rinha de Backend 2024 Q1 was concurrency management for a bank statements and transactions scenario. This repository shows my code written in C# and Postgres database to handle it. It is not for production, just fun.

License

felipeoriani/rinha-backend-24q1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rinha de Backend 2024 Q1 - felipeoriani

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.

⚠️ This code was designed speficically for the Rinha de Backend and it is not recommened to be part of any prod/final solution. It is just fun!

💻 Lessons Learnt:

  • Windows dynamic ports can block the Load Testing after some time;
  • Handle concurrency in Postgres with pg_advisory_xact_lock vs FOR UPDATE;
  • ConnectionPool configurations for Postgres, 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 including Native AOT in .NET 8 and speed up the process and the runtime;
  • Linux Ubuntu setup for .NET (I used to use just Windows);

Stack:

logo .NET logo CSharp logo PostgreSql logo Nginx

🏃 How to Run

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

🧪 Load Testing Results

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:

image

Thank you.

About

2024 - The proposed of Rinha de Backend 2024 Q1 was concurrency management for a bank statements and transactions scenario. This repository shows my code written in C# and Postgres database to handle it. It is not for production, just fun.

Topics

Resources

License

Stars

Watchers

Forks