Event Driven Architecture vs REST API: Production Trade-offs
When choosing between event driven architecture vs REST API, the decision comes down to coupling and latency tolerance. REST works best when clients need immediate responses and strong consistency. Event driven systems shine when services can operate independently and eventual consistency is acceptable. Most production systems I run end up using both.
Core architectural differences and communication patterns
REST APIs follow a request-response model. The client sends a request, blocks, and waits for a response. This synchronous coupling means the caller knows exactly when the operation succeeds or fails. It also means the caller is blocked until the callee responds. If the downstream service is slow or down, the upstream request times out or fails.
Event driven architecture flips this. Services emit events to a message broker. Consumers process those events asynchronously. The producer does not wait. It does not even know who consumes the event. This decouples services in time and space. A service can go down, come back up, and process the backlog without the producer noticing.
In my FastAPI services, a typical REST endpoint looks like this:
@router.post("/orders", response_model=OrderResponse)async def create_order(order: OrderCreate, db: AsyncSession = Depends(get_db)): new_order = await order_service.create(db, order) await payment_service.charge(new_order.payment_id, new_order.amount) await inventory_service.reserve(new_order.items) await notification_service.send_confirmation(new_order.user_id, new_order.id) return new_orderEvery downstream call adds latency. A failure in any step rolls back the whole request. The client waits for all of it.
The event driven equivalent publishes a single event and returns immediately:
@router.post("/orders", response_model=OrderResponse, status_code=202)async def create_order(order: OrderCreate, db: AsyncSession = Depends(get_db)): new_order = await order_service.create(db, order) await event_bus.publish("order.created", OrderCreatedEvent.from_order(new_order)) return new_orderSeparate consumers handle payment, inventory, and notifications. Each can retry independently. The API responds in milliseconds instead of seconds.
When to choose event driven over synchronous REST
Choose REST when the client genuinely needs the result now. Payment confirmation, user login, and lookup queries fit this pattern. The user stares at a spinner until the response arrives. Synchronous calls make the flow obvious and debugging straightforward.
Choose event driven when the work can happen later. Sending emails, generating reports, updating search indexes, and syncing data to third parties are classic examples. The user does not need to wait for the welcome email to arrive before seeing “account created.”
I learned this the hard way on a checkout service. We called three external APIs synchronously. When one provider had a 30-second outage, our entire checkout queue backed up. Users saw 504s. Moving the external calls to async consumers with exponential backoff eliminated the cascade. The trade-off is eventual consistency. The order shows “pending” for a few seconds. That is acceptable for checkout. It would not be acceptable for a balance transfer.
Hybrid architectures combining both patterns
Pure event driven systems are rare. Pure REST systems are common but brittle at scale. The sweet spot is hybrid. Use REST for the write path that requires immediate feedback. Emit events for side effects and downstream propagation.
A pattern I use frequently in FastAPI: the API handler validates, persists the core entity, publishes an event, and returns. Background workers consume the event. This keeps the API fast and the domain logic decoupled.
class OrderService: async def create(self, db: AsyncSession, order: OrderCreate) -> Order: order_obj = Order(**order.model_dump(), status="pending") db.add(order_obj) await db.flush() await self.event_bus.publish("order.created", order_obj.id) return order_objThe event payload stays small. Consumers fetch the full entity from the database if needed. This avoids event schema bloat and keeps the source of truth in one place.
For internal service-to-service calls that need a response, I still use HTTP. But I wrap them in a circuit breaker and enforce strict timeouts. The FastAPI background tasks pattern works well for fire-and-forget work that does not need durability. For anything that must not be lost, use a proper message broker.
Migration strategies from REST to event driven
Migrating a synchronous call graph to event driven is risky if done all at once. I prefer the strangler fig approach. Identify one downstream call that is slow, flaky, or independent. Extract it to an event consumer. Keep the REST call in place but make it fire-and-forget with a local outbox table.
The outbox pattern prevents event loss during the transition. Write the event to an outbox table in the same transaction as the business data. A separate publisher reads the outbox and forwards to the broker. This guarantees at-least-once delivery without distributed transactions.
CREATE TABLE outbox ( id BIGSERIAL PRIMARY KEY, event_type VARCHAR(100) NOT NULL, payload JSONB NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW(), published_at TIMESTAMPTZ);Once the consumer is stable and monitored, remove the synchronous call from the API handler. Repeat for the next downstream dependency. This incremental approach lets you roll back each step independently.
I also recommend reading about event driven architecture vs request response trade-offs to understand the consistency implications before you start.
Error handling and observability comparison
REST error handling is straightforward. The HTTP status code tells the client what happened. 4xx means fix the request. 5xx means retry or alert. Logs correlate request IDs across services.
Event driven error handling is harder. A failed consumer does not automatically notify the producer. You need dead letter queues, retry policies, and alerting on consumer lag. I configure exponential backoff with a maximum retry count. After exhaustion, the message goes to a DLQ. An on-call engineer inspects the DLQ, fixes the root cause, and replays.
Observability shifts from request tracing to event tracing. You need correlation IDs that flow through the event payload. OpenTelemetry helps, but you must instrument the producer, the broker, and every consumer. Metrics to watch: consumer lag, processing latency, error rate per event type, and DLQ size.
One mistake I made: treating events as commands. Events are facts. “OrderCreated” not “CreateOrder.” Commands imply a single handler. Events imply zero or many consumers. This distinction matters when you add a new consumer six months later and realize the payload is missing a field the new service needs.
Technology stack recommendations for each approach
For REST, FastAPI with Pydantic and SQLAlchemy async is my default. It gives automatic validation, OpenAPI docs, and solid performance. Add httpx with a circuit breaker for outbound calls. Use Redis for caching and rate limiting.
For event driven, the broker choice depends on scale and team familiarity. Kafka handles high throughput and replay. RabbitMQ is simpler for lower volume and complex routing. Redis Streams works if you already run Redis and need lightweight streams. I avoid managed services like SQS or EventBridge unless the team has zero ops capacity. Vendor lock-in hurts during debugging.
Schema registry is non-negotiable. Use Confluent Schema Registry with Avro or Protobuf. JSON schemas work but lack evolution guarantees. I have spent days debugging a consumer crash caused by a producer adding a required field without a default. Schema registry catches that at deploy time.
For the FastAPI side, lifespan events handle broker connections cleanly. See FastAPI lifespan vs startup events for the modern pattern.
FAQ
Can I use event driven architecture with a monolith?
Yes. A modular monolith can emit domain events to an in-process bus or a local message queue. This prepares you for service extraction later without distributed system complexity today.
How do I handle distributed transactions across event driven services?
Use the saga pattern. Each service performs its local transaction and emits an event. Compensating actions handle failures. The outbox pattern ensures events are never lost.
Is REST faster than event driven for simple CRUD?
Yes. For straightforward create-read-update-delete with no side effects, REST adds less overhead. Event driven introduces broker latency and serialization costs that are not justified for simple operations.
What is the biggest mistake teams make when adopting event driven?
Treating events as RPC. If you find yourself waiting for a response event or correlating request IDs manually, you have built distributed RPC with extra steps. Use REST for that flow.
Key Takeaways
- REST provides synchronous coupling and immediate consistency. Use it for user-facing write paths and queries.
- Event driven provides asynchronous decoupling and eventual consistency. Use it for side effects, integrations, and high-throughput pipelines.
- Hybrid architectures give you the best of both. Emit events from REST handlers for downstream work.
- Migrate incrementally using the outbox pattern. Never rewrite the entire call graph at once.
- Invest in schema registry, dead letter queues, and correlation ID tracing from day one.
- Choose your broker based on team expertise and throughput needs, not hype.
Working on something similar?
If you're building backend or AI systems and want a second set of senior eyes, let's talk.