My own product · 2026 · in production
Kravva
A football prediction platform with rankings, pools, a store with PIX payments, live scores, a news portal with an AI-assisted newsroom, and communities. I build and run it on my own, from product to infrastructure.
- 16BullMQ queues
- 31back-end modules
- 96migrations
- 2environments: production and staging
The problem
I wanted a product of my own, with a real back end. Kravva is a football prediction platform: users predict scores, join pools, compete in rankings, follow matches live and buy passes via PIX (Brazil's instant payment system). It has a store, affiliates and a social layer.
That sounds simple until the match starts. The score changes and everyone wants to see it right away. Points have to be recalculated at the final whistle. The sports data API has a daily quota. And money comes in through a webhook, which the provider resends whenever it wants.
I was the only person to handle all of it, from product to deploy.
What I did
Modular back end
The API is a modular monolith in NestJS 11 with PostgreSQL 16: 31 modules, 82 entities and 96 migrations. The migrations are hand-written SQL, and CI applies all of them to an ephemeral Postgres before any deploy. Auth uses JWT with refresh tokens, Google SSO and RBAC.
Queues for everything that doesn't fit in a request
There are 16 BullMQ queues: live match sync, scoring, notifications, email and data retention for the LGPD (Brazil's data protection law). Jobs use deterministic IDs. That way the same goal or the same final whistle is never processed twice.
Real time across a cluster
The API runs as a Node cluster, with more than one worker. Socket.io uses the Redis adapter and JWT authentication on the handshake. When a purchase is confirmed or the score changes, the event leaves the worker that processed it and reaches the user's socket, whichever worker it is on.
PIX with webhook and ledger
The webhook arrives with an HMAC signature over the raw body, which I validate with a constant-time comparison. Confirmation runs in a transaction with a pessimistic lock on the payment row and writes to an append-only financial ledger. A refund is a new entry, never an update.
// Idempotent confirmation (pseudocode)
await db.transaction(async (tx) => {
const pagamento = await tx.selectForUpdate(pagamentos, { id }); // lock the row
if (pagamento.status === 'pago') return; // webhook redelivery: nothing to do
pagamento.status = 'pago';
await tx.save(pagamento);
await ledger.registrarSeAusente(tx, pagamento); // append-only entry
await acessos.concederSeAusente(tx, pagamento);
await comissao.creditar(tx, pagamento); // only on the first confirmation
});
// The real-time event only goes out after the commit
emitirParaUsuario(pagamento.usuarioId, 'acesso_liberado');
If the webhook is late, the front end checks the transaction. After some time pending, the API asks the provider and calls the same idempotent path.
Operations
Background routines need to run in a single process, so I elect a leader through a lease in PostgreSQL. Deploys are automated with GitHub Actions and SSH to a VPS running Docker and Nginx. The front end is on Cloudflare Pages and files are on R2. There is a production environment and a staging environment, and large releases are rehearsed in staging against an anonymized copy of production, with guards that refuse to run against the real database.
AI-assisted newsroom
The newsroom suggests story ideas on its own from Kravva's data (today's match, post-match, a finished round, a computed fact), without spending any AI. To write, the editor starts from a research dossier with data and sources, and the LLM returns the draft as strict structured output, with adapters for Anthropic and OpenAI. A checker verifies the numbers, style rules block facts without a source, and the editor picks one of three headlines. Media comes from Wikimedia Commons, filtered by license and credited. A person always publishes: the AI helps assemble, the editor decides.
Portal, communities and LGPD
Articles go out on Kravva's own portal, with a share image generated on first read for WhatsApp and social previews. Communities bring a monthly league, prediction pools, a schedule and supporter passes, with rules tied to the Terms of Use and moderation with reports, removal and appeals. LGPD compliance runs end to end: cookie consent, marketing emails only with adult opt-in, and account deletion with a final payout of the balance.
Decisions and trade-offs
Layered idempotency for payments. Event history, SELECT ... FOR UPDATE, state checks and unique indexes as the last barrier. I chose a pessimistic lock because payment providers resend in bursts and the critical section is short. The cost: concurrent deliveries of the same payment wait for each other.
BullMQ with deterministic jobId. The queue guarantees at-least-once delivery, so processing has to tolerate repeats. The job ID prevents duplicates. The cost: deduplication only holds while the job is retained. I've already had to consider including the score in the ID so that a VAR correction would create a new job.
Hand-written SQL migrations. They give control over partial indexes and backfills, which the TypeORM generator handles poorly. The cost: nothing guarantees the entity still matches the real column. That depends on discipline and tests.
Cluster instead of an orchestrator. Two workers make use of the machine without the complexity of Kubernetes. The cost shows up in the next point: in-memory state per process.
Result
Kravva is in production, with automated deploys, unit tests with Jest, integration tests against a real Postgres and CI that dry-runs the migrations. I don't disclose the number of users.
Three real incidents turned into fixes:
- WebSocket dropping in the cluster. The front end got "Session ID unknown" (HTTP 400). The cause: Nginx wasn't passing the WebSocket upgrade through, the client fell back to long polling, and requests from the same client landed on different workers. I added the Socket.io block to Nginx with
Upgrade, and the error went away. That was a separate problem from the Redis adapter, which I added in the same change to fix a silent failure: an event emitted on one worker didn't reach sockets connected to another. - Football API quota blown during the World Cup. I switched to a live snapshot shared between workers and a global rate limiter in Redis.
- PWA serving stale files after deploy. I handled chunk recovery and
skipWaiting.
On AI: a good part of the code was written with help from Cursor and Claude. The decisions, the review and the operations are mine, and I can explain each of them.
What I'd do differently
I'd start with observability: structured logs, queue metrics and alerts. That's a gap I'm aware of.
I'd break up the match sync service, which has grown too large.
I'd close the long polling fallback with pure WebSocket or sticky sessions. Without that, polling stays fragile with more than one worker.
I'd standardize data access, which today mixes custom repositories with TypeORM's default repository.