Back to Projects

One seat left of four. Avery's day shows the booked reservation and the redeemed tap. One reservation sits in the dead-letter list, and the fail switch is off.

Dayline

Java / Spring Boot

JavaKafkaDynamoDBReactive

Dayline is a Java 21 service for a guest's day. A return window is inventory in MySQL. A JSON booking and an XML hotel feed both write the same reservation, and the seat count drops only when remaining is still above zero. A turnstile tap redeems that reservation once. The command and the outbox row commit together. A publisher sends the row to Kafka, keyed by guest id. A Reactor Kafka consumer projects the event into DynamoDB with the async client. A failed projection retries, then lands on a dead-letter topic. Replay writes a new outbox row and does not touch inventory again. The running console is https://dayline.apps.onpoint.host. Source is https://github.com/launchthatbrand/dayline.

The ledger and the phone

Seats left, unpublished rows, and dead letters come from MySQL. The day on the left is the DynamoDB projection for the selected guest. Avery's tap was accepted once. A later reservation was forced to fail and is waiting on replay.

MySQL
Ledger

Windows, reservations, taps, and the outbox commit in one transaction

DynamoDB
Phone read

Partition key is the guest. Sort key is the event time plus the event id

Once
Tap

The idempotency key is guest, window, and tap id

Reactor
Stream

Bounded concurrency on the flux, then a dead-letter topic

The Problem

The phone wants the guest's day now, and the gate wants a tap that cannot redeem twice. Those are different reads. If both hit the same row, a slow projection holds the seat update, and a second tap from a flaky reader creates a second redemption.

The Solution

MySQL is the ledger. Booking, the hotel feed, the tap, and cancel all run in one Spring MVC transaction with an outbox row. Kafka topic guest.events carries the change, keyed by guest id. The stream process is a Reactor Flux: flatMap writes the itinerary through DynamoDbAsyncClient and does not block the event loop. The phone reads DynamoDB. The operator console reads MySQL for seats, taps, and dead letters.

Ledger, then the phone

The guest console, the hotel feed, and the turnstile all call the same command API. MySQL commits the seat change with an outbox row. The publisher sends that row to guest.events. The stream process projects it into DynamoDB. A projection that exhausts its retries is published to guest.events.dlq. The operator console reads the ledger, the taps, and that dead letter.

Technical Decisions

Key architecture decisions and their outcomes

Commands stay on Spring MVC

Context

A booking has to decrement the remaining count and insert the reservation and the outbox row together. A reactive stack would split that transaction across a different client.

Decision

The API is Spring MVC with JDBC. The reactive stack is only the stream process, which reads Kafka and writes DynamoDB.

Outcome

A failed seat update rolls the reservation back. The consumer never holds a MySQL transaction open while it talks to DynamoDB.

One reservation shape for JSON and XML

Context

A guest can book from the phone, and a partner hotel sends the same stay as XML.

Decision

POST /api/reservations takes JSON. POST /api/feeds/hotel takes an XML hotelStay. Both call the same book method and store source as json or xml.

Outcome

The outbox payload and the DynamoDB item do not care which feed created the reservation.

The async DynamoDB client stays async

Context

Reactor Kafka already delivers a Flux. Blocking inside flatMap would pin the event loop for every guest.

Decision

putItem goes through DynamoDbAsyncClient and Mono.fromFuture. Retries use Retry.backoff. The JDBC fail switch and the dead-letter insert run on a bounded elastic scheduler.

Outcome

A projection that fails twice is published to guest.events.dlq and recorded in MySQL. The offset is acknowledged after that record exists.

Replay does not move inventory

Context

The seat was already taken when the reservation committed. Projecting it again must not take another seat.

Decision

Replay inserts a new outbox row with the same event id and the stored payload. It does not update remaining.

Outcome

After the fail switch is off, replay projects the guest's day and clears the dead-letter row.

Engineering Details

  • POST /api/windows opens inventory. Booking runs UPDATE windows SET remaining = remaining - 1 WHERE remaining > 0
  • The tap key is guestId:windowId:tapId. A duplicate returns the original row and does not publish
  • The publisher reads one unpublished outbox row with FOR UPDATE SKIP LOCKED and sends it to guest.events with acks=all
  • The consumer uses a concurrency of 4. A claimed fail-next flag dead-letters that event, and a later replay of the same event id is allowed through
  • DynamoDB Local stands in on the cluster. The table is itinerary, partition guestId, sort sk
  • Testcontainers covers MySQL, Kafka, and DynamoDB Local: book, duplicate tap, XML feed, cancel, and a projection that fails and is replayed
  • The same image runs as dayline-api and dayline-stream. Production equivalents are RDS for MySQL, Amazon MSK, and DynamoDB. The GitHub Action is the build, verify, and deploy path

Key Highlights

  • Java 21 and Spring Boot 3, one image with an api command and a stream command
  • Conditional seat update and the outbox row commit together
  • JSON booking and an XML hotel feed write the same reservation
  • A duplicate tap returns the original redemption and does not publish again
  • Reactor Kafka projects the day with DynamoDbAsyncClient
  • Replay publishes the stored event again and leaves inventory alone

Tech Stack

Skills & Technologies

Related Projects