Event and Webhook Scaling: The Art of Ordering from Synchronous to Asynchronous

WorkOS shares cross-database ordering challenges after asynchronous event capture and trade-offs such as entity-level ordering keys.
The WorkOS team shared the ordering challenges their SaaS platform faced as event capture shifted from synchronous to asynchronous. In the synchronous model, event writes and business operations shared the same database transaction, so order was naturally determined by commit order, but this hurt latency and throughput. After switching to asynchronous, events were no longer written atomically with business operations; auto-increment IDs could still preserve order within a single database, but ordering became complex across the business and event databases. WorkOS's strategies include assigning ordering keys by business entity to ensure entity-level ordering, adopting a transactional outbox to keep events consistent with business state, using asynchronous queues and retry mechanisms, and requiring Webhook consumers to implement idempotency to handle duplicates and out-of-order delivery. The article emphasizes that global ordering is costly and usually only entity-level ordering is needed, and offers developer recommendations such as clarifying the scope of ordering and monitoring/alerting.
When building modern SaaS platforms, events and Webhooks are the bridge connecting systems to the outside world. But as business scale grows and event capture shifts from synchronous to asynchronous, ordering issues come to the surface. The WorkOS team recently shared their experience and trade-offs in this transition: why guaranteeing event order within a single database is easy, why it becomes exceptionally difficult across two systems, and how they ultimately maintained ordering.

The Simplicity of the Synchronous Era
In the early architecture, event capture and business operations were completed within the same database transaction. This meant that event order was naturally determined by the database's commit order, and developers hardly needed to worry about out-of-order issues. WorkOS mentioned in their blog that this synchronous model allowed them to easily send Webhooks in order, because event writes and business state updates were atomic.
However, as event volume grew, the synchronous model began to show bottlenecks. Every business operation had to wait for the event write to complete, which increased latency and reduced system throughput. So the team decided to make event capture asynchronous to improve performance and scalability.
The Ordering Challenges Brought by Asynchrony
Once event capture became asynchronous, events were no longer written within the same transaction as business operations. This meant that events could arrive at the storage layer in a different order, especially across multiple services or databases. WorkOS pointed out that within a single database, order can still be maintained through auto-increment IDs or timestamps, but once two databases are involved (for example, a business database and an event database), guaranteeing order becomes complex.
The original text states: "Why event ordering is easy within one database but hard across two, and the trade-offs we made at WorkOS to preserve ordering after making event capture asynchronous."
To solve this problem, WorkOS adopted an event ordering key strategy: assigning each event a sequence number based on the business entity, ensuring that events for the same entity are processed in order. At the same time, they introduced asynchronous queues and retry mechanisms, but had to carefully handle duplication and out-of-order issues caused by retries.
The Transactional Outbox pattern is a classic solution to the consistency problem of asynchronous event publishing: within the same local transaction of the business database, the event to be published is written to a dedicated "outbox" table, so that business data and event records either commit together or roll back together, ensuring events are not lost and remain consistent with business state. A separate publishing process (or a CDC tool such as Debezium) then polls or subscribes to the outbox table and delivers events to the message queue. Because the outbox table usually has an auto-increment primary key or a strictly increasing sequence, the publishing process can read in write order, naturally obtaining ordering guarantees within a single database; in cross-database scenarios, records need to additionally carry an entity-level ordering key, and downstream systems perform partitioning and serial processing by that key. This pattern sacrifices a small amount of write overhead and publishing latency in exchange for "at-least-once" delivery and a replayable, persistent event log.
Ordering key and entity-level ordering: In distributed messaging systems, global ordering means all events must pass through a single partition for serial processing, which limits throughput and creates obvious hot spots. In practice, a partition key mechanism is usually adopted—each event carries a stable identifier (such as tenant ID, order ID, or aggregate root ID), and the messaging middleware routes events with the same key to the same partition accordingly, thereby maintaining first-in-first-out order within the partition. What this yields is "entity-level ordering": different entities can be processed in parallel, while state changes for the same entity are strictly ordered. When designing ordering keys, attention must be paid to their stability (they must not change with event content) and granularity (too coarse leads to hot spots, too fine loses the meaning of ordering), and it must be ensured that the same key value is still used during retries and replays.
Trade-offs and Solutions
Under the asynchronous architecture, WorkOS faced several key trade-offs:
- Ordering vs. latency: Strict ordering may increase latency because events need to wait for the previous event to finish processing. WorkOS chose to guarantee ordering at the entity level rather than globally, thereby balancing latency and correctness in most scenarios.
- Duplication and idempotency: Asynchronous retries may cause duplicate events, so Webhook consumers need to implement idempotent handling. WorkOS emphasized this in their documentation.
- Cross-database consistency: By introducing an event log and ordering keys, they were able to maintain order across databases, but this required additional storage and coordination overhead.
WorkOS's practice shows that in asynchronous event capture, completely avoiding out-of-order delivery is nearly impossible, but the impact can be minimized through sound design. Their approach includes using the transactional outbox pattern to ensure consistency between event writes and business operations, and leveraging ordering keys to guarantee entity-level ordering.
Idempotency means that executing the same operation multiple times produces the same result as executing it once. Under "at-least-once" delivery semantics, retries and duplicates are unavoidable, and Webhook consumers must deduplicate on their own. Common practices include: assigning each event a globally unique event ID, and having consumers check a processed-records table (or a deduplication cache such as Redis) before processing to determine whether it has already been consumed; placing business processing and "mark as processed" in the same transaction to ensure atomicity; and using unique constraints or optimistic locking for write operations so that duplicate requests naturally fail rather than producing side effects. It should be noted that idempotent design should cover every side effect in the processing flow (such as sending notifications or deducting inventory), not just the final database write; otherwise, partial duplicate execution may still occur.
Takeaways for Developers
For developers building similar systems, WorkOS's experience offers several references:
- Clarify the scope of ordering: Global ordering is costly; usually it is only necessary to guarantee ordering at the entity or aggregate root level.
- Adopt a transactional outbox: Place event writes and business operations in the same transaction, then publish asynchronously; this avoids event loss and preserves ordering.
- Design idempotent Webhook consumers: Because asynchronous retries are unavoidable, consumers must be able to handle duplicate events.
- Monitor and alert: Monitor event latency and out-of-order delivery to detect anomalies in time.
WorkOS's sharing reveals a detail in event-driven architecture that is often overlooked: ordering is not just a technical issue, but also a cornerstone of business correctness. As systems move from synchronous to asynchronous, developers need to find the balance between performance and ordering.
CDC (Change Data Capture) is a common alternative or supplement to the transactional outbox: it parses the database's write-ahead log (such as PostgreSQL logical replication slots or MySQL binlog) and converts row-level changes into an event stream in real time, without explicitly writing to an outbox table in business code. Because events originate directly from the database commit log, their order is consistent with transaction commit order, naturally satisfying single-database ordering. However, CDC also introduces new complexity: replication slots and consumer offsets must be maintained, schema changes must be handled, log bloat must be addressed, and the publishing pipeline is tightly coupled to business table structures. Choosing between outbox and CDC usually depends on the team's preferences regarding invasiveness, operational cost, and latency.
Conclusion
Event ordering is a classic challenge in distributed systems. WorkOS's practice shows that through transactional outbox, ordering keys, and idempotent design, acceptable ordering guarantees can be maintained under an asynchronous architecture. For any SaaS platform that relies on Webhooks, these lessons are worth learning from.
One-line Summary
WorkOS shares the cross-database ordering challenges after making event capture asynchronous and trade-off solutions such as entity-level ordering keys.
Paragraph Summary
The WorkOS team shared the ordering challenges their SaaS platform encountered as event capture shifted from synchronous to asynchronous. In the synchronous model, event writes and business operations were in the same database transaction, so order was naturally determined by commit order, but this hurt latency and throughput. After switching to asynchronous, events were no longer written atomically with business operations; auto-increment IDs could still maintain order within a single database, but ordering became complex across the business database and event database. WorkOS's strategies include assigning ordering keys by business entity to ensure entity-level ordering, adopting a transactional outbox to keep events consistent with business state, using asynchronous queues and retry mechanisms, and requiring Webhook consumers to implement idempotency to cope with duplicates and out-of-order delivery. The article emphasizes that global ordering is costly and usually only entity-level ordering is needed, and offers developer recommendations such as clarifying the scope of ordering and monitoring/alerting.
Related articles

Samsung Tests Recompose Feature: Change the Viewing Angle After Taking a Photo
Samsung One UI 9.5 beta code reveals a Recompose feature based on the existing Move tool that may let users adjust a photo's viewpoint after capture. We analyze its technical logic, user value, and launch prospects.

Nimble's Detachable Power Bank Drops $20 — Is It Worth Buying?
Nimble SharePower 10,000mAh detachable power bank drops to $59.96, a $20 discount and all-time low. We analyze its detachable design, pricing, and buying advice across all four colors.

An Author Under a Gag Order: Sarah Wynn-Williams on 'Careless People'
Sarah Wynn-Williams, author of Careless People, discusses living under a gag order in a Guardian interview, exploring its impact on writers and platform power.