Architecture Patterns
Decouple Receipt from Processing
Return 200 immediately, process asynchronously. The most critical pattern for reliable webhook handling is separating acknowledgment from processing.1
Receive the webhook
Your endpoint receives the POST request from Smartcar
2
Persist immediately
Write the raw payload to a queue, database, or object storage
3
Return 200
Acknowledge receipt with a 200 status code (within 15 seconds)
4
Process asynchronously
A background worker processes the persisted payload
- Prevents timeouts from slow business logic
- Allows you to retry processing without requesting redelivery
- Enables you to update processing logic without losing historical events
- Survives temporary outages in downstream systems
Security
Always Verify Signatures
Every webhook payload includes anSC-Signature header containing an HMAC-SHA256 signature. Always verify this signature before processing the payload.
Python
- Confirms the payload came from Smartcar
- Prevents spoofed requests from malicious actors
- Protects against replay attacks
Reliability
Implement Idempotency
Use theeventId field to ensure you process each event exactly once, even if Smartcar retries delivery or you reprocess from your queue.
- Smartcar retries failed deliveries with the same
eventId - Your queue worker might process the same message multiple times
- Prevents duplicate database updates or notifications
Handle Delivery Order
Webhook events are delivered concurrently and may arrive out of order. Don’t assume events arrive in chronological order. Use timestamps to determine freshness:- Network delays can cause events to arrive out of sequence
- Retries of older events may arrive after newer events
- Last-write-wins without timestamps can cause stale data
Monitoring & Observability
Log Everything
Comprehensive logging helps you debug issues, monitor performance, and understand user behavior. Key events to log:Webhook Receipt
Webhook Receipt
Signature Verification
Signature Verification
Processing Start/End
Processing Start/End
Processing Errors
Processing Errors
Set Up Alerts
Monitor critical metrics and alert on anomalies:- Signature verification failures - May indicate spoofed requests
- Processing error rate - High errors suggest code or infrastructure issues
- Queue depth - Growing backlog indicates processing can’t keep up
- Response time - Approaching 15s timeout threshold
- Duplicate event processing - Idempotency checks are catching issues
Error Handling
Handle VEHICLE_ERROR Events
Don’t ignoreVEHICLE_ERROR events. They indicate signal retrieval failures and require action.
| Error Type | Meaning | Action |
|---|---|---|
VEHICLE_NOT_CAPABLE | Signal not supported by vehicle | Remove from subscription or mark as N/A |
PERMISSION_ERROR | Missing permission scope | Prompt user to reconnect with required permissions |
UPSTREAM_ERROR | Temporary OEM failure | Log and monitor; usually resolves automatically |
RATE_LIMIT | Too many requests | Back off temporarily |
Graceful Degradation
Design your system to continue functioning when webhook processing fails. Example strategies:Fallback to Polling
Fallback to Polling
If webhook processing fails, temporarily fall back to REST API polling for critical data.
Partial Data Handling
Partial Data Handling
If some signals fail, process the successful ones and mark failed signals as unavailable.
Dead Letter Queue
Dead Letter Queue
Route persistently failing events to a dead letter queue for manual investigation.
Circuit Breaker
Circuit Breaker
Stop processing webhooks if downstream dependencies are down, return 503 to trigger retries later.
Testing
Test in Development
Use the Smartcar Dashboard to trigger test webhook deliveries before going to production.1
Set up local tunnel
Use ngrok or similar to expose your local server:
2
Configure webhook
Set your ngrok URL as the callback URI in Dashboard
3
Trigger test events
Use the Dashboard to send test
VEHICLE_STATE and VEHICLE_ERROR events4
Verify handling
Check logs to confirm signature verification, queuing, and processing work correctly
Validate Edge Cases
Test your integration handles these scenarios:- Duplicate deliveries - Same
eventIddelivered multiple times - Out-of-order events - Older events arriving after newer ones
- Invalid signatures - Reject payloads with wrong signature
- Partial signal failures - Some signals succeed, others error
- Large payloads - Maximum 50KB payload size
- Missing fields - Gracefully handle unexpected payload structure
Performance
Optimize Response Time
Your endpoint must respond within 15 seconds. Optimize for speed:Do
- Return 200 immediately after persisting
- Use in-memory queues (Redis, SQS)
- Keep webhook handler logic minimal
- Use database connection pooling
Don't
- Make API calls before responding
- Write to slow storage (S3, disk)
- Perform complex calculations
- Wait for downstream services
Scale Horizontally
Design for horizontal scaling to handle growing webhook volume:- Stateless webhook receivers - Any instance can handle any request
- Distributed queues - SQS, RabbitMQ, Kafka for cross-instance communication
- Load balancer health checks - Return 200 on
/healthendpoint - Auto-scaling policies - Scale based on queue depth or CPU

