Implement Idempotency
Use theeventId field to ensure you process each event exactly once, even if Smartcar retries delivery or you reprocess from your queue.
Why Idempotency Matters
- Smartcar retries failed deliveries with the same
eventId - Your queue worker might process the same message multiple times
- Prevents duplicate database updates or notifications
- Enables safe reprocessing of historical events
Implementation Strategies
- Redis
- DynamoDB
- PostgreSQL
Handle Out-of-Order Delivery
Webhook events are delivered concurrently and may arrive out of order. Never assume events arrive in chronological sequence.Use Timestamps for Freshness
Always check if incoming data is newer than your current stored state:Why Order Matters
Network Delays
Network Delays
Events sent at different times may experience different network latencies, causing them to arrive out of sequence.
Retry Timing
Retry Timing
If an older event fails initially and is retried later, it might arrive after newer events that succeeded on first attempt.
Concurrent Delivery
Concurrent Delivery
Smartcar delivers events concurrently for performance. Events sent milliseconds apart might arrive in reverse order.
Timestamp-Based Updates
Handle Retries Gracefully
Smartcar automatically retries failed deliveries up to 3 times with exponential backoff.Retry Identification
Each delivery attempt receives a uniquedeliveryId, but the eventId remains constant:
Processing Strategy
1
Check for duplicate eventId
Use idempotency check to skip already-processed events
2
Process the payload
Perform your business logic
3
Mark as processed
Store the eventId to prevent reprocessing
4
Return 200
Acknowledge successful processing
Transactional Processing
Ensure database updates and idempotency tracking happen atomically:Recovery Strategies
Dead Letter Queue
Route persistently failing events to a dead letter queue for manual investigation:Circuit Breaker
Stop processing if downstream dependencies are failing:Next Steps
Monitoring
Track idempotency hits and processing failures
VEHICLE_ERROR Events
Handle error notifications and resolution tracking
Delivery Behavior
Understanding retry policies
Testing
Test retry scenarios

