The problem

A POS or ERP — Automotive, BR Logística, Happy Pet — should not talk to the SII. Numbered folios, POS retries, and isolation between businesses are issuance problems, not sales-screen problems. The SII is left out on purpose: no signed XML and no homologation. The focus is the invariants, not a real receipt.

What I built

A Boleta 39 microservice: one process, one database, one HTTP contract. Full source (not a sample). It comes up with docker compose up.

Technical decisions

Hexagonal architecture so a real SII can land later without rewriting the domain. Multi-tenant in three layers: tenant comes only from the JWT (Keycloak), Hibernate filters by tenant_id, and PostgreSQL applies RLS. Outbox in the same transaction; DteIssued to RabbitMQ after commit.

The hard problem

No folio, no DTE. Reservation uses pessimistic locking per tenant: N parallel POSTs, no gaps or duplicates. Required Idempotency-Key: a POS retry returns the same document; a different body → 409.

The outcome

Keycloak login, idempotent POST, Alpha issues and Beta gets 404. Portfolio artifact — not production fiscal software.