All case studies
Case study
Removing a webhook race condition with database-level idempotency
Replacing a check-then-insert on subscription webhooks with a UNIQUE constraint, so concurrent duplicate deliveries can no longer create duplicate transactions.
- Context
- Subscription payments via RevenueCat webhooks
- Role
- Backend
- Key point
- UNIQUE(transaction_id)
- PostgreSQL
- RevenueCat webhooks
- Go / Node.js
The problem
Webhook providers can deliver the same event more than once.
The naive handler ran SELECT, then INSERT if nothing was found. Two concurrent deliveries could both see 'not found' and both insert.
Architecture: before → after
- SELECT transaction_id
- Not found?
- INSERT (race between concurrent requests)
- INSERT
- UNIQUE(transaction_id)
- Duplicate → safely rejected
What I did
- Added a UNIQUE constraint on transaction_id and let the insert itself decide.
- A duplicate delivery now fails the constraint and is safely acknowledged instead of processed twice.
Outcome
- Removed the race condition between concurrent webhook deliveries.
- Simpler handler: the database is the single source of truth for idempotency.
More case studies
- Scaling a high-traffic microservices backend on AWS
- Making cache synchronisation resilient with SQS, retries and a DLQ
- A realtime social platform that scales horizontally
- Protecting SMS OTP endpoints from automated abuse
- Leading delivery decisions under deadline pressure