Architecture
Event-Driven Architecture: A Practical Guide for Small Teams and VPS Setups
By NileVPS Team · Published · 5 min read
اقرأ المقال بالعربيA customer places an order. The order service then has to charge the card, reserve stock, send a confirmation email, notify the warehouse, update analytics and award loyalty points. If it calls each of those services directly and waits for every answer, one slow email provider makes checkout slow, and one crashed analytics service makes checkout fail. Event-driven architecture flips the design: the order service records the fact "order placed" and publishes it, and every interested component reacts in its own time. This article explains how that works, when it is worth it, and how to run it on ordinary servers.
Core concepts
An event is a fact about something that already happened. It is named in the past tense: OrderPlaced, PaymentFailed, UserRegistered. The producer does not know or care who listens.
A command is a request for something to happen. SendEmail or ChargeCard targets a specific handler and expects it to act. Mixing the two causes confusion, so keep the distinction clear in naming.
The main roles are:
- Producer: publishes events when its state changes.
- Broker: stores and delivers events, for example Redis Streams, RabbitMQ, NATS or Apache Kafka.
- Consumer: subscribes to events and reacts, ideally independently of other consumers.
A typical event looks like this:
{
"id": "01JD8Z3K6Q2V7N4X9T5R1M8P0C",
"type": "OrderPlaced",
"version": 1,
"occurred_at": "2026-11-22T10:15:30Z",
"data": { "order_id": 1842, "customer_id": 77, "total": 950.00, "currency": "EGP" }
}A unique id lets consumers detect duplicates, and a version lets you evolve the schema without breaking old consumers.
Benefits and costs
| Benefit | Cost that comes with it |
|---|---|
| Loose coupling: add consumers without touching the producer | Harder to see the full flow; you need tracing and good logs |
| Resilience: a down consumer catches up later | Eventual consistency; data is not updated everywhere instantly |
| Absorbs spikes: the broker buffers work | A broker to run, monitor and back up |
| Natural audit trail of what happened | Duplicates and out-of-order delivery must be handled |
If your application is a single service with a single database and modest traffic, a background job queue may give you most of the benefit with less complexity. Event-driven design pays off when several components need to react to the same facts, or when you want slow side effects out of the request path.
Choosing a broker
- Redis Streams: simple, fast, and probably already on your server. Consumer groups give at-least-once delivery with acknowledgements. Good for small and medium workloads.
- RabbitMQ: flexible routing with exchanges and queues, mature tooling and a management UI. Good when different consumers need different subsets of events. See our queue systems article for more.
- NATS with JetStream: lightweight, low latency, easy clustering.
- Kafka: a durable, partitioned log designed for very high throughput and replay. It is powerful, but it is more to operate than most small teams need.
A minimal example with Redis Streams
Producer:
redis-cli XADD orders '*' type OrderPlaced order_id 1842 total 950Create a consumer group once, then read and acknowledge:
redis-cli XGROUP CREATE orders email-service '$' MKSTREAM
redis-cli XREADGROUP GROUP email-service worker-1 COUNT 10 BLOCK 5000 STREAMS orders '>'
redis-cli XACK orders email-service <message-id>Each consumer group, such as email-service or analytics, gets its own copy of every event. Workers within a group share the load. Messages that are read but not acknowledged stay pending, so XPENDING and XAUTOCLAIM let another worker pick them up after a crash. Cap stream growth with XADD orders MAXLEN ~ 1000000 '*' ....
The dual-write problem and the outbox pattern
The most common bug in event-driven systems is this sequence: save the order to the database, then publish the event. If the process crashes between the two steps, the order exists but nobody hears about it. Publishing first has the opposite problem.
The transactional outbox fixes it. Write the event into an outbox table in the same database transaction as the business change:
BEGIN;
INSERT INTO orders (id, customer_id, total) VALUES (1842, 77, 950);
INSERT INTO outbox (event_type, payload) VALUES ('OrderPlaced', '{"order_id":1842}');
COMMIT;A separate relay process reads unsent outbox rows, publishes them to the broker and marks them sent. Either both the order and the event exist, or neither does.
Rules that keep consumers sane
- Assume at-least-once delivery. Every consumer must be idempotent; store processed event IDs or use natural keys. Our idempotency guide shows how.
- Do not rely on global ordering. Order is usually guaranteed only per partition or per stream. Include versions or timestamps and ignore stale updates.
- Use dead-letter queues. After a few failed attempts, move the event aside for inspection instead of retrying forever.
- Version your events. Add fields freely; never remove or repurpose them without a new version.
- Monitor lag. Consumer lag, meaning how far a group is behind the head of the stream, is the single most useful health metric.
- Keep payloads small. Send identifiers and key facts, not entire database rows.
A single VPS can comfortably host a broker, a few producers and several consumers while you are small, and you can split them across servers as you grow. See /pricing for options.
FAQ
Is event-driven architecture the same as microservices?
No. Microservices describe how you split an application into deployable units. Event-driven architecture describes how components communicate. You can use events inside a single monolith, for example with an in-process event bus, or build microservices that only talk over synchronous HTTP.
Do I need Kafka to go event-driven?
No. Many systems run well on Redis Streams, RabbitMQ or NATS. Kafka makes sense for very high volumes, long retention and replaying history at scale. Start with the simplest broker that meets your durability needs.
How do I handle a consumer that was down for hours?
If the broker retains events, the consumer resumes from its last acknowledged position and works through the backlog. Make sure retention covers your longest expected outage, and that consumers can process faster than events arrive so they actually catch up.