Prompt
I need a decision guide for streaming vs queueing in a microservices system
Latest observation
Here’s a practical decision guide for streaming vs queueing in a microservices system.
Quick rule of thumb
- Use a queue when you want to get work done once, reliably, and you do not need every consumer to see every event.
- Use streaming when you want to publish a sequence of events that can be replayed, consumed by multiple services, or processed continuously.
Core difference
Queue
- A message is typically handled by one consumer
- Supports work distribution
- Messages are often removed after processing
- Best for commands and jobs
Streaming
- An event is part of an ordered log
- Multiple consumers can read the same event stream independently
- Messages are retained for a period and can be replayed
- Best for events and event-driven pipelines
When to choose a queue
Choose a queue if you need:
1. One-time task execution
Examples:
- Generate an invoice PDF
- Send a notification email
- Resize an image
- Run a background cleanup job
2. Load leveling / backpressure
If producers can spike faster than consumers can handle, queues help buffer the load.
3. Simple worker scalability
Add more workers and let them share the load.
4. Strong “do this task” semantics
A queue is a good fit for commands:
- “Charge this card”
- “Send this email”
- “Recalculate this report”
5. Minimal replay needs
If you only care about processing once and don’t need historical event reprocessing, a queue is often simpler.
When to choose streaming
Choose streaming if you need:
1. Event propagation to multiple services
Examples:
OrderPlacedconsumed by billing, shipping, analytics, inventory
2. Replayability
You may want to:
- Rebuild projections
- Reprocess data with new logic
- Recover from downstream bugs
3. Ordered event history
Useful when the sequence of events matters.
4. Continuous processing
Examples:
- Fraud detection
- Clickstream analytics
- Real-time metrics
- Monitoring pipelines
5. Event sourcing or CQRS
If the system’s source of truth is an append-only event log, streaming is a natural fit.
Decision matrix
| Need | Prefer Queue | Prefer Streaming |
|---|---|---|
| One consumer handles a task | ✅ | |
| Multiple consumers need same message | ✅ | |
| Replay past messages | ✅ | |
| Simple background job processing | ✅ | |
| Event-driven architecture | ✅ | |
| Ordered event log | ✅ | |
| Work distribution among workers | ✅ | |
| Real-time analytics | ✅ | |
| Temporary buffering of tasks | ✅ | |
| Long-lived event retention | ✅ |
Important architectural distinction
Queues are best for “commands”
A command asks a service to do something:
ProcessPaymentCreateShipmentReindexSearch
Commands are usually:
- Directed at a specific service
- Expected to be handled once
- Not necessarily interesting to other services
Streams are best for “events”
An event says something happened:
PaymentProcessedShipmentCreatedSearchIndexUpdated
Events are usually:
- Broadcast to interested consumers
- Immutable
- Useful beyond the service that produced them
Common pitfalls
Don’t use a queue when you really need an event log
If multiple services need the same data, or you need replay, a queue can become limiting.
Don’t use streaming just because it sounds modern
If all you need is background job execution, streaming can add unnecessary complexity:
- partitioning
- offsets
- retention
- consumer lag
- schema evolution
Don’t treat events like RPC
Streaming is not a replacement for synchronous service calls. If a caller needs an immediate answer, use sync APIs or a request/reply pattern.
Latency and scale considerations
Queue
- Usually simpler for task latency
- Good for burst handling
- Often easier to operate for small-to-medium systems
Streaming
- Better when throughput is high and consumers process independently
- Can handle very large event volumes
- More operationally complex, but more powerful
Reliability considerations
Queue reliability patterns
- Retry with dead-letter queue
- Idempotent consumers
- Visibility timeout / ack semantics
Streaming reliability patterns
- Consumer offsets/checkpoints
- Replay for recovery
- Idempotent processing
- Schema versioning
Both need:
- Idempotency
- Retry handling
- Observability
- Dead-letter or poison message strategy
Practical examples
Use a queue for:
- Email sending
- Thumbnail generation
- OCR jobs
- Batch ETL task execution
- Periodic report generation
Use streaming for:
- Order lifecycle events
- Audit logs
- User activity tracking
- IoT telemetry
- Fraud/risk scoring
- Search indexing pipelines
Hybrid approach
Many systems use both:
- Queue for internal work distribution
- Stream for domain events and analytics
Example:
OrderServicewritesOrderPlacedto a streamBillingService,ShippingService, andAnalyticsServiceconsume itNotificationServicemay use a queue for sending emailsImageServicemay use a queue for asynchronous processing
This is often the most realistic design.
Simple selection checklist
Ask these questions:
-
Do I need every consumer to see the same message?
- Yes → streaming
- No → queue
-
Do I need replay or reprocessing?
- Yes → streaming
-
Is this a task/job rather than a domain event?
- Yes → queue
-
Do I need ordered history over time?
- Yes → streaming
-
Is the system mainly about background work execution?
- Yes → queue
-
Is the system mainly about event propagation and integration?
- Yes → streaming
Recommendation summary
- Choose queueing for task-oriented, one-consumer, work-distribution use cases.
- Choose streaming for event-oriented, multi-consumer, replayable, ordered use cases.
- Use both when building a mature microservices platform.
If you want, I can also turn this into:
- a one-page architecture decision record (ADR),
- a flowchart, or
- a technology-specific guide for Kafka, RabbitMQ, SQS, or Azure Service Bus.