Back to Projects

Event-Driven System with Transactional Outbox

100+ events/min, <1s latency, 100% delivery guarantee, 4 domain event types

Production-ready event-driven backend implementing the Transactional Outbox Pattern — the canonical solution to the dual-write problem in distributed architectures, used at scale by Netflix, Uber, and Amazon. Guarantees atomic, exactly-once event delivery across service boundaries without distributed transactions or two-phase commit. Routes 4 domain event types (USER_CREATED, ORDER_PLACED, PAYMENT_RECEIVED, INVENTORY_UPDATE) through a strict three-state lifecycle machine with sub-second latency, HikariCP connection pooling, type-based multi-path routing, and idempotency enforcement to make the entire pipeline self-healing.

Java 23PostgreSQL 18n8nHikariCP 5.1.0JDBCSLF4J 2.0.9PostgreSQL JDBC 42.7.4

Problem

In distributed systems, writing to a database and publishing to an event bus in a single atomic operation is inherently unreliable — if the DB write succeeds but the message publish fails (or vice versa), data silently diverges across service boundaries with no clean, consistent recovery path.

Solution

Applied the Transactional Outbox Pattern: events are written atomically into an outbox table inside the same DB transaction as the business operation, guaranteeing zero message loss. A separate n8n async processor polls the table, routes events by type to the correct handler, transitions each event through a strict state machine (PENDING → PROCESSING → COMPLETED), and enforces idempotency to eliminate duplicate side-effects.

Key Highlights

  • Solves the dual-write problem atomically — no distributed transactions or 2-phase commit needed
  • Outbox write is part of the same DB transaction as business logic, guaranteeing zero message loss
  • Three-state lifecycle machine: PENDING → PROCESSING → COMPLETED with strict transition enforcement
  • Type-based multi-path event routing across 4 domain event types with isolated handler logic
  • Idempotent event processing — duplicate delivery never produces duplicate side-effects
  • HikariCP 5.1.0 connection pool for high-throughput, low-latency DB access under load
  • n8n async workflow engine with 60-second polling and externally configurable credentials
  • Prepared statements throughout — zero SQL injection surface area by design
  • Structured SLF4J logging with per-event audit trail for production operational visibility
  • Horizontally scalable: multiple n8n worker instances can process event partitions in parallel