rinha2-back-end-go

Challenge

Rinha de Backend 2024/Q1

Rinha de Backend is a Brazilian backend programming challenge. The 2024/Q1 edition models a tiny financial API: five predefined clients start with credit limits and zero balances, and the service must accept concurrent credits, debits, and statement reads under a strict container resource cap.

Required API contract

EndpointMethodExpected behaviorCurrent implementation note
/clientes/{id}/transacoesPOSTSubmit a debit (d) or credit (c) transaction for clients 1 through 5.Implemented in postTransacaoHandler; returns id, limite, and updated saldo.
/clientes/{id}/extratoGETReturn current balance, credit limit, statement timestamp, and recent transactions.Implemented in getExtratoHandler; returns saldo and up to 10 ultimas_transacoes.

The repository also exposes GET /healthz for compose/CI health checks; it is not part of the original banking contract.

Seeded clients

ClientLimit
1100000
280000
31000000
410000000
5500000

The same IDs and limits appear in both the Go clientes map and the SQL seed data.

Validation rules

Current validation is split between Go and PostgreSQL:

  • Non-integer client IDs return 400 from the Go handlers.
  • Client IDs outside 1–5 return 404 before the database call.
  • Invalid JSON transaction bodies return 400.
  • tipo must be exactly debit (d) or credit (c).
  • descricao must be non-empty and at most 10 characters.
  • valor must be greater than zero.
  • Debits cannot push the balance below -Limite; credits are allowed unconditionally.
  • Invalid transaction fields return 422.

Resource constraints

The official stack budget is intentionally tight:

Total CPU1.5

Shared across API, NGINX, and PostgreSQL.

Total RAM550MB

Shared across all challenge-counted containers.

Workloadk6

Concurrent transactions, validations, and statement queries.

Why this implementation is interesting

The repository explores a compact Go approach: a small HTTP layer, a simple NGINX fan-out, and PostgreSQL stored procedures for the hot transaction path. The goal is not to build a feature-complete banking system; it is to study performance trade-offs under a fixed resource envelope.

Source specification

Full specification: github.com/zanfranceschi/rinha-de-backend-2024-q1