Executive Summary
1 min summary
Regulatory-driven platforms face sudden adoption cliffs rather than gradual organic growth, bringing 50,000 clients in month one under strict data sovereignty and 14-year audit retention rules. Surviving that cliff required separating GDPR-erasable data from immutable audit records, modeling multi-company tax advisor permissions across frontend and backend, decoupling traffic with Kafka and the Gruelbox transactional outbox, and replacing H2 and internal Jenkins with PostgreSQL in Testcontainers and GitHub Actions. For CTOs and engineering leaders, compliance boundaries, async decoupling, and production-parity CI must be built on day one before a statutory launch date arrives.
Most B2B software gets a grace period. You launch to a few dozen early adopters, hit a few rough edges, fix your locking bugs, and slowly grow into your architecture over a year.
Regulatory software doesn’t work like that. When a national e-invoicing mandate lands, thousands of businesses and tax advisors show up on the same calendar date because they have to. On a European e-invoicing platform I helped build on Java, PostgreSQL, Angular, and CloudFoundry, we went from zero to 50,000 clients in the first month.
At that pace, every shortcut you postponed for “after launch” comes due in week one. Four contradictions collide at once: tax law demands 14-year retention while GDPR demands deletion, one tax advisor switches between dozens of client companies inside a single browser session, month-end invoice spikes slam into synchronous database transactions, and green H2 integration tests quietly hide real PostgreSQL locking bugs.
Data Sovereignty and the 14-Year Audit Horizon
In European accounting software, compliance shapes storage and integration boundaries from day one. Two rules drove almost every early decision:
- Strict data sovereignty. Invoices contain sensitive commercial and tax data. Customer records and payloads had to stay inside approved regional infrastructure, which ruled out casually bolting on third-party SaaS queues, external managed caches, or cross-region analytics pipelines.
- 14-year audit retention. Statutory and policy retention rules on the platform meant we had to preserve invoices and their full audit trail for fourteen years in an auditable, tamper-evident form.
Fourteen years outlives most frameworks, half your database schemas, and several generations of the engineering team. Treating audit data as a side effect of application logging or dumping untyped JSON blobs into a write-only table falls apart fast once real auditors or customers start asking questions.
We treated compliance data and the audit trail as a first-class model with three strict requirements:
- A dedicated data type for every auditable entry. Rather than squeezing every event into a generic message string, each audit entry used an explicit typed schema capturing actor, company context, timestamp, target document, and event-specific attributes, versioned cleanly so historical entries stay readable years later.
- Customer-facing visibility and search. Audit logs locked in cold storage do not help a customer answering a tax auditor. We separated hot operational state from immutable archival storage while keeping structured audit metadata indexed and searchable by company, actor, document reference, event type, and date range under strict tenant isolation.
- Trigger-driven deletion separating GDPR data from 14-year statutory records. Tax rules demand keeping statutory invoice records for fourteen years, while GDPR demands deleting personal and operational data once no legal basis remains. Keeping both in the same table makes deletion requests impossible without breaking retention. We split the model explicitly so automated deletion triggers erase personal fields without touching statutory archives:
Designing the audit model this way forced discipline early, especially once we brought multi-company tax advisors onto the same platform. Every action had to be traceable to both the individual user and the exact client company they were acting for.
One Management Platform, Multi-Company Tax Advisors
From the user’s perspective, the system was a single multi-tenant management platform with one shared Angular and TypeScript frontend sitting in front of multiple Java services on CloudFoundry. Companies and tax advisors logged into one place to view incoming invoices, track processing states, manage outbound documents, and handle exceptions.
If you design a B2B SaaS platform assuming “one user belongs to one company,” you will get burned the moment tax advisors log in.
In European accounting, a single tax advisor often manages dozens or hundreds of separate client companies. They sit in the same browser session all day, jumping from Client A’s incoming invoices to Client B’s approvals, while holding completely different permission sets for each company. An advisor might be allowed to approve and dispatch invoices for one client, have read-only access for another, and have zero visibility into a third.
Making that work cleanly across one frontend and multiple backend services required treating active company context + scoped permissions as a first-class concern on both sides:
- Explicit tenant context on every request. The frontend never relied on implicit session state or cached global user roles. Switching the active company updated the tenant context explicitly, cleared tenant-scoped client state so stale data from Company A could never flash on Company B’s screen, and re-evaluated UI capabilities for that specific company.
- Backend enforcement on every boundary. Frontend permission checks only control what buttons render. Every backend endpoint resolved the caller’s rights for the specific target company on every request, and every repository query was scoped to that tenant ID. No service trusted a company ID or role list handed over by the browser without verifying authorization against the rights management layer.
Getting advisor multi-tenancy right took real coordination between the Angular frontend and Java backend teams, and it paid off immediately. Under a 50,000-client launch, a single cross-tenant data leak or wrong-company approval would have been an existential trust failure.
Decoupling Invoice Traffic Through Kafka
Strict tenant boundaries kept the management UI safe, but interactive user clicks were only half the load. Behind the platform, PostgreSQL handled both relational transactional state and structured invoice payloads stored in JSONB columns. Keeping both inside PostgreSQL avoided cross-store distributed transactions and let versioned payloads evolve alongside strict relational audit metadata, provided every payload carried an explicit schema-version tag so readers could still parse 14-year-old documents cleanly.
The bigger threat was billing-cycle spikes starving that shared database. So the first runtime boundary we protected was the path between user interactions in the UI and actual invoice traffic.
Invoice ingestion and outbound sending ran through Kafka, completely decoupled from the management APIs. When thousands of clients upload or receive batches of structured invoices at the end of a billing cycle, Kafka absorbs the spike without starving the web UI or timing out upstream partners. Each stage of the pipeline (validation, format checks, enrichment, routing, and dispatch) could scale and retry independently.
Breaking Synchronous Chains with Gruelbox
Even with Kafka handling core invoice ingestion and sending, the management platform still had to coordinate with multiple internal services: document archives, validation engines, master data, notification pipelines, and downstream accounting modules.
Early on, synchronous service-to-service HTTP calls create a familiar trap. A user triggers an action, Service A writes to PostgreSQL, calls Service B, which calls Service C. When Service B slows down under month-one load or restarts during a CloudFoundry deploy, Service A’s database transaction stays open, connection pools drain, and a timeout leaves you guessing whether the downstream side succeeded or failed.
To break those synchronous chains without falling into the dual-write trap (which I wrote about in more detail in Where the Tracks Divide), we adopted the transactional outbox pattern using Gruelbox (transactionoutbox).
Here is a simplified illustration of how a service commits its business state and records the outgoing relay work inside the exact same PostgreSQL transaction:
@Transactional
public void approveOutboundInvoice(UUID invoiceId, String tenantId) {
InvoiceRecord record = invoiceRepository.findByIdAndTenant(invoiceId, tenantId)
.orElseThrow(() -> new InvoiceNotFoundException(invoiceId));
record.markApproved();
invoiceRepository.save(record);
// Persisted in the same PostgreSQL transaction; relayed asynchronously after commit
outbox.schedule(InvoiceDispatchRelay.class)
.publishApprovedInvoice(record.getId(), tenantId);
}
Once PostgreSQL commits, Gruelbox’s background worker picks up the pending entry, executes the relay (pushing to Kafka or calling the downstream integration), and retries with backoff if the target is temporarily unavailable. If the business transaction rolls back, the outbox entry rolls back with it.
That single shift eliminated a whole class of partial-failure bugs. Slow downstream services stopped cascading into user-facing timeouts, retries became explicit and observable instead of hidden in HTTP client loops, and our PostgreSQL transactions stayed short and predictable under load.
There are real trade-offs to weigh before dropping an outbox into every service. Outbox relays deliver at least once, which means every downstream consumer has to be idempotent so a retry after a network blip never dispatches a duplicate invoice. The outbox table itself also sees heavy insert-and-delete churn, so PostgreSQL indexing, retention, and autovacuum settings need attention once volume climbs.
If a service only updates local state with no critical cross-service side effects, skip the outbox and keep the code simple.
Rule of thumb: Never make a synchronous HTTP call to another service inside a
@Transactionaldatabase boundary on a high-volume workflow. Commit locally with an outbox entry and let an idempotent async relay handle downstream slowness.
Hardening the Delivery Loop: Testcontainers and GitHub Actions
Moving critical coordination into PostgreSQL and Gruelbox immediately exposed a quieter problem: our local tests and CI pipeline no longer matched production reality. Two unglamorous engineering upgrades proved just as important as the architecture itself.
Moving Local Development from H2 to PostgreSQL in Testcontainers
Like many Java codebases, local development and integration tests originally leaned on an embedded H2 database because it started in a second. The problem with H2 is that it lies to you politely.
H2 does not enforce the same SQL dialect rules, JSONB column behavior, index quirks, transaction isolation, or row-level locking semantics as PostgreSQL. When your reliability depends on JSONB queries and a transactional outbox polling under concurrency (such as FOR UPDATE SKIP LOCKED), H2 gives you green builds that fail the first time real Postgres handles concurrent workers.
We migrated local development and integration tests from H2 to real PostgreSQL running in Testcontainers. Startup cost a few extra seconds, and in return real migration bugs, JSONB schema mismatches, and concurrency locking defects surfaced on developer laptops instead of waiting for launch week.
What to check: If your production stack relies on PostgreSQL locking, JSONB columns, or a transactional outbox while your test suite still runs on H2, your green CI build is hiding launch-week bugs.
Moving CI from Internal Jenkins to GitHub Actions
Alongside the database shift, we migrated our build and deployment pipelines from an internal Jenkins setup to GitHub Actions.
Shared internal Jenkins instances tend to age into fragile snowflakes: opaque Groovy scripts, plugin drift, and long queues where teams hesitate to add thorough integration tests because builds already take too long. Moving to GitHub Actions put pipeline definitions directly in the repository alongside the code, made container-based Testcontainers runs reliable out of the box, and shortened the feedback loop between opening a pull request and knowing whether a change was safe to ship (the exact kind of CI parity check I always inspect first during a 2-week architecture review).
When you are onboarding tens of thousands of clients in a single month, fast and trustworthy CI is your safety net. If a hotfix takes an hour to fight through a flaky build server, small production glitches turn into long outages.
Four Checks Before a Regulatory Launch Cliff
If you are building a financial or compliance platform with a hard statutory launch date, the load curve will not forgive “we’ll harden it once we have traction.” Run these four checks before the calendar decides for you:
- Run a dry-run GDPR erasure against a 14-year invoice record. If deleting a user’s personal data breaks your statutory archive or forces manual SQL cleanup, your retention and compliance boundaries are still tangled together.
- Test a multi-company power user switching tenants mid-session. Log in as an advisor, broker, or partner admin with different rights across three companies, switch rapidly in one browser tab, and verify that both UI state and every backend repository query honor the active tenant.
- Audit every
@Transactionalmethod for outbound HTTP calls. If a downstream timeout can hold a database connection open during a month-end spike, decouple bulk flow through Kafka and move cross-service side effects into an idempotent transactional outbox. - Check what database and CI runner actually sign off your pull requests. If production depends on PostgreSQL locking and
JSONBwhile tests run on H2 behind a slow, snowflake Jenkins box, migrate to PostgreSQL in Testcontainers and repo-native CI before launch-week hotfixes depend on it.
A regulatory mandate does not wait for your second architecture iteration. Holding the fence on day one comes down to resolving those four contradictions before the first 50,000 clients arrive.
Preparing for a high-volume regulatory launch or hardening a multi-tenant financial platform? A fixed-scope 2-Week Architecture Review pinpoints scaling, compliance, and delivery bottlenecks before launch traffic hits, or share one bottleneck via the contact form for three candid observations within 48 hours.