From nightly batch to real time
At a glance
Section titled “At a glance”| Aspect | Aspect |
|---|---|
| Typical organization | A retailer, lender, insurer or logistics company whose systems exchange data in overnight jobs |
| Symptoms | Stock, balances or order status are a day old; nightly jobs overrun; failures found in the morning |
| Root cause | Integration built on scheduled file exports and bulk loads |
| Usual fix | Capture changes as they happen and stream them to every system that needs them |
| Patterns | Event-driven architecture, messaging, change data capture, transactional outbox |
Sound familiar?
Section titled “Sound familiar?”- The website shows items in stock that sold out this morning.
- Customer service can’t see a payment made an hour ago.
- The overnight batch window is full, and a late job delays everything the next day.
- When a nightly job fails, the business finds out at 9 a.m.
- Fraud or risk checks run hours after the transaction.
Why it happens
Section titled “Why it happens”Batch integration was the natural choice when systems were few and overnight was quiet. As the business moved online and around the clock, the overnight window shrank and expectations of freshness rose. The batch jobs themselves are rarely the problem; it’s that the data only moves once a day.
Your options
Section titled “Your options”| Option | When it fits | Cost and risk |
|---|---|---|
| Run batches more often | Freshness of an hour is enough | Low. Quick, but load and failure handling get harder |
| Change data capture (CDC) from the database log | The source can’t easily be changed to publish events | Medium. Little change to the source; events mirror tables |
| Publish business events from the application, with an outbox | You own the source application | Medium. Events carry business meaning, such as “order placed” |
| Call APIs synchronously | One consumer needs an answer immediately | Low to medium. Couples systems tightly if overused |
A proven approach
Section titled “A proven approach”- Start with the freshness that matters most, such as stock levels or payment status, and agree a target, for example “within one minute”.
- Capture changes at the source, with CDC for systems you can’t change and an outbox for those you can, so an event is never lost when a database write succeeds.
- Stream them through a durable, replayable broker, so new consumers can start from any point and failed ones can catch up.
- Make consumers idempotent, because events can arrive more than once.
- Keep the batch running in parallel until the streaming path is proven, then retire it.
- Applications you own write an event to an outbox table in the same transaction as their data.
- A relay publishes outbox events to a durable broker.
- Change data capture reads the log of databases you can't change.
- Every consumer receives changes within seconds and can replay history if it falls behind.
Trade-offs and what to watch
Section titled “Trade-offs and what to watch”- Ordering and duplicates. Events can arrive out of order or twice; design consumers for both.
- Schema changes now break consumers in real time. Version events and register their schemas.
- More moving parts to operate: a broker, connectors and consumer lag to monitor.
How you’ll know it worked
Section titled “How you’ll know it worked”Data reaches consumers within the agreed time, the batch window shrinks or disappears, and failures are noticed in minutes instead of the next morning.
Seen in the real world
Section titled “Seen in the real world”- LinkedIn streamed database changes and activity through Kafka.
- Uber cut data latency from a day to under an hour with incremental ingestion.
- Stripe shows why safe retries need idempotency.
Related on ArchitectureCompass
Section titled “Related on ArchitectureCompass”Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.