How micheloliveira-com/rinha-de-backend-2025-dotnet-csharp-postgres works
Project type and purpose
• This is a high-performance, containerized backend API (“Rinha de Backend 2025”) implemented in .NET 10 with AOT for minimal startup time and resource usage.
• It exposes endpoints to enqueue payments, process them asynchronously, and return aggregated summaries under a distributed lock.
File structure
• src/backend: Contains the .NET solution with Program.cs, HTTP handlers (CountingHandler), domain models (Record.cs), services (PaymentService, PaymentProcessorService, PaymentBatchInserterService, PaymentSummaryService, ConsoleWriterService) and a RedisQueueWorker.
• Configuration files: appsettings.json, launchSettings.json, Dockerfile.
• Docker Compose files at src/: docker-compose.yml / override / .dcproj orchestrate four containers (backend, nginx, redis, postgres).
• init.sql seeds the PostgreSQL schema.
• nginx.conf configures the NGINX reverse proxy.
Extract architecture from README
• Two .NET AOT backend instances behind an NGINX load balancer.
• Redis acts as both message queue and backing store for the ReactiveLock distributed lock.
• PostgreSQL persists payments via bulk inserts (batch of 100).
• ReactiveLock synchronizes flushes before returning the payments summary.
• Services are built with Dapper.AOT, Polly for retries, and ReactiveLock.Distributed.Redis.
Main components & their relationships
a. External Client (HTTP/JSON)
b. NGINX Load Balancer (reverse proxy & round-robin)
c. Backend Instances (1 & 2)
• HTTP Handler → PaymentService enqueues to Redis
• RedisQueueWorker dequeues → PaymentProcessorService → PaymentBatchInserterService → PostgreSQL
• PaymentSummaryService under ReactiveLock reads from PostgreSQL → HTTP response
d. Redis
• Message queue for workers
• Backing store for ReactiveLock coordination
e. PostgreSQL
• Bulk insertion store for processed payments
f. ReactiveLock
• Distributed lock library coordinating flush + summary across instances
Architectural patterns & design principles
• Queue-based asynchronous processing (Redis ← HTTP enqueue)
• Bulk-write optimization for high throughput
• Distributed coordination (ReactiveLock) for consistency on summary reads
• Resilience and retry logic (Polly) on external calls
• Containerized deployment using Docker Compose
• Separation of concerns: Handlers → Services → Workers → Data stores