Throughput
Suppose you need to process 100,000 transactions per second.
REST
Every request:
- Opens/uses connection
- Executes logic
- Returns response
The API server becomes the bottleneck.
Kafka
Messages are:
- Batched
- Sequentially written to disk
- Consumed independently
Kafka is designed for extremely high throughput.
Winner for throughput:
✅ Kafka
Example:
- Website clickstream events
- Telemetry data
- IoT sensor data
- Log aggregation
Scalability
REST
Scaling often means:
- More API instances
- Load balancers
- Database scaling
All consumers hit the same API.
Kafka
You can independently scale:
- Producers
- Brokers
- Consumer groups
If traffic doubles:
- Add more consumers
- Rebalance partitions
Winner:
✅ Kafka
Reliability Under Load
REST
If a downstream service is unavailable:
- Requests timeout
- Retries increase load
- Cascading failures may occur
Kafka
Messages remain in the broker:
- Consumers can be offline
- Processing resumes later
- No message loss (with proper configuration)
Winner:
✅ Kafka
Fan-Out Performance
Suppose an order event must be consumed by:
- Billing service
- Inventory service
- Analytics service
- Notification service
REST
Order Service
|
|--> Billing API
|--> Inventory API
|--> Analytics API
|--> Notification API
Many network calls.
Kafka
Order Service --> Kafka Topic
Billing Consumer
Inventory Consumer
Analytics Consumer
Notification Consumer
Single publish, many consumers.
Winner:
✅ Kafka
Resource Usage
REST
Good for:
- Interactive user operations
- CRUD applications
- Real-time queries
Kafka
Good for:
- Massive event streams
- Decoupled microservices
- Event sourcing
- Data pipelines
| Aspect | REST API | Kafka |
|---|---|---|
| Communication | Synchronous | Asynchronous |
| Latency | Very low (milliseconds) for direct request | Slightly higher end-to-end due to broker hop |
| Throughput | Limited by API server capacity | Extremely high (millions of messages/sec possible) |
| Scalability | Scale API servers horizontally | Scale producers, brokers, and consumers independently |
| Reliability | Client retries required | Built-in persistence and replay |
| Backpressure handling | Difficult | Native consumer lag handling |
| Fan-out to multiple consumers | Multiple API calls needed | Publish once, consume many times |
| Real-time response | Excellent | Not ideal for immediate response |
No comments:
Post a Comment