Prompt
How do I build event-driven integrations between apps
Latest observation
To build event-driven integrations between apps, the basic idea is:
- one app publishes events when something happens
- another app subscribes to those events and reacts
- a broker, bus, or stream layer usually moves the events between them
1) Start with the event contract
Define the event as a stable message format.
Example:
{
"event_type": "order.created",
"event_id": "evt_123",
"occurred_at": "2026-10-19T10:15:00Z",
"source": "orders-service",
"version": 1,
"data": {
"order_id": "ord_456",
"customer_id": "cus_789",
"total": 120.50
}
}
Good practices:
- use clear event names like
user.created,invoice.paid - include a version
- make events self-contained
- avoid sending only database IDs if the receiver needs more context
2) Choose an integration pattern
Common options:
Publish/subscribe
Best when multiple apps need the same event.
Examples:
- Kafka
- RabbitMQ
- Google Pub/Sub
- AWS SNS + SQS
- Redis Streams
Webhooks
Best for simpler point-to-point integrations.
Example:
- your app sends an HTTP POST to a partner app when an event happens
Event streaming
Best when you need replay, ordering, and high throughput.
Examples:
- Kafka, Pulsar
3) Make one app emit events reliably
Don’t publish an event until the business action succeeds.
Common approach:
- update your database
- write an event record in the same transaction
- publish asynchronously
This is often called the outbox pattern.
Why it matters:
- prevents “database updated but event not sent”
- helps with retries and reliability
4) Build consumers that are idempotent
Consumers should safely process the same event more than once.
Why:
- retries happen
- brokers may redeliver
- network failures are normal
Typical technique:
- store
event_id - ignore duplicates already processed
5) Handle retries and failures
Design for failure from day one.
Use:
- retry with backoff
- dead-letter queues
- alerting for repeated failures
- poison-message handling
Rules of thumb:
- retry transient errors
- move permanently bad messages aside
- don’t block the whole queue because one event is bad
6) Secure the integration
Treat events like API traffic.
Use:
- authentication between producer and broker
- authorization per topic/queue/webhook
- TLS in transit
- signing for webhooks
- secret rotation
For webhooks:
- sign payloads with HMAC
- include timestamp and nonce to prevent replay attacks
7) Define delivery semantics clearly
Decide what guarantee you need:
- At-most-once: may lose events, no duplicates
- At-least-once: no loss if possible, but duplicates can happen
- Exactly-once: hard to achieve in practice; usually approximated
Most real systems use at-least-once + idempotent consumers.
8) Plan for schema evolution
Events change over time.
Use:
- versioned schemas
- backward-compatible changes
- schema registry if needed
Safe changes:
- add optional fields
- keep old fields for a while
Risky changes:
- renaming/removing fields without versioning
9) Observe the pipeline
Add monitoring for:
- event publish rate
- consumer lag
- processing failures
- retry counts
- dead-letter queue size
- end-to-end latency
Logs and traces should include:
event_idcorrelation_idsourceversion
10) A practical architecture example
Imagine an e-commerce app:
orders-servicecreates an order- it emits
order.created inventory-servicereserves stockbilling-servicecharges paymentnotifications-servicesends email- each consumer acts independently
This decouples the services:
- they don’t need direct synchronous calls
- each can fail/retry independently
Simple implementation path
If you’re starting small:
- define event payloads
- pick a broker or webhook mechanism
- implement producer
- implement one consumer
- add idempotency
- add retries and monitoring
- expand to more consumers
If you want to build this in code
I can show you:
- a webhook-based integration
- a Kafka/RabbitMQ example
- an AWS event-driven setup
- a Node.js / Python / Java implementation
If you tell me your stack and whether this is app-to-app, internal microservices, or third-party integrations, I can give you a concrete design.