Data syncing
Keep your app in sync with WorkOS.
Syncing your app data with WorkOS is done using events. Events represent activity that has occurred within WorkOS or within third-party identity and directory providers that interact with WorkOS.
When important activity occurs, we record an event. For example, a new SSO connection being activated is an event. A user being created, assigned membership to an organization, or successfully signing in are all events as well. Events are activity that your application might be interested in for the purposes of syncing data or extending your application’s business logic.
Your app can consume events from WorkOS via either the events API or webhooks.
With the events API, your application retrieves events from WorkOS. The events API offers a more robust data synchronization solution compared to webhooks, ensuring seamless synchronization of your system state with WorkOS. To sync data using the events API, continue to the events API guide.
With webhooks, WorkOS automatically notifies your app when an event occurs by invoking an endpoint hosted within your application. To sync data using webhooks, continue to the webhooks guide.
With the WorkOS sync engine, your WorkOS data is mirrored into a Postgres database you control, so you can query it with SQL and join it to your own application data. The engine combines the events API for live changes, the list endpoints for historical data, and a reconciliation step that detects drift, so you do not have to build and operate that pipeline yourself. To mirror your data into Postgres, continue to the Postgres sync guide.
We recommend using the Events API instead of webhooks to keep your data in sync – especially for user and directory events. With the Events API, you control how often and how much data you ingest. Webhooks, on the other hand, require your endpoint to handle unpredictable spikes in event volume, which can make them harder to manage at scale. That said, webhooks may still be the better fit depending on your use case. If you want the result in your own database rather than in your own event handler, the sync engine builds on the Events API and adds backfill and reconciliation. Here’s how the options compare:
| Aspect | Events API | Webhooks | Postgres sync |
|---|---|---|---|
| Timing | Controlled by your app. Your server can process events at its own pace. | Real-time. Webhooks trigger as soon as an event occurs. | Controlled by your app. Data is queried from your own database, seconds behind. |
| Order | A consistent order is guaranteed. | No guarantee of order on receipt. Events contain timestamps to determine order. | Guaranteed. Stale updates are rejected on write. |
| Reconciliation | Replayable. Can go back to a specific point in time and reprocess events. | Failed requests are retried with exponential back-off for up to 3 days. | Replayable, plus a set-difference check that detects missed deletes and creates. |
| Security | Authentication, confidentiality, and integrity protection by default. | You must expose a public endpoint and validate webhook signatures. | Authenticated pull. No public endpoint required. |