Preventing Duplicate Side Effects in Event-Driven Systems
说明与用途
在事件驱动系统中,重复交付可能导致外部操作重复。解决方案是使用业务级幂等键、唯一数据库约束、显式状态机和重试分类。
问题
Event-driven systems can deliver the same event multiple times, leading to duplicate side effects when external actions are performed without proper idempotency.
结果
By shifting from event-level to business-level idempotency and adding durable state, retries became safe, eliminating duplicate side effects and improving system reliability at scale.
工作流
- Receive external event via webhook
- Validate and persist event with stable identity
- Enqueue for processing
- Create or claim business action with unique key (account_id+automation_id+source_event_id+action_type)
- Insert action record with unique constraint
- Perform idempotent external API call using same key
- Update durable state to COMPLETED
- Log metrics and trace identifiers
证据
The real problem appears after the action has been claimed. Consider: Create action → Call external API → External API succeeds → Worker crashes → Completion state is never written.
If the external API supports idempotency keys, use them. The same logical operation should always carry the same key.
- 记录日期: 2026-09-13T10:31:58.667Z