DataSync
DataSync lets you store and synchronize application data directly on PubNub and keep every connected client up to date in real time, without adding an external database or building your own sync layer. You define your data model using the Admin API, then client apps create, update, and read records at runtime through the SDK. Changes to your data are delivered as real-time events over the same channels your app already subscribes to, and every request is authorized by Access Manager.
DataSync entities and SDK entities are different things
These pages are about DataSync entities: the records the service stores and treats as the source of truth for your application state.
An SDK entity is a local, client-side handle such as a Channel handle for room-1. It carries no stored state of its own. The two meet in DataSync SDK entities, SDK entities whose only job is to subscribe to a DataSync object's real-time updates.
How it works
You define classes (types) for your data, create instances of those classes, and PubNub stores them, validates the fields you declared on the class, and optionally publishes their changes as events.
Everything you store is an instance of a class. Most classes are ones you define using the Admin API, and a few are built in: PubNub seeds User, Channel, and Membership for you. See Data model for how these building blocks relate to each other.
Classes and instances live on two different clocks. Your team defines a class once, using the Admin API, and every client then creates and reads instances of it at runtime. Instances are validated against the properties declared on the class and optionally projected to the caller's projection on every request.
The flow runs in four steps:
- Your team defines classes and event rules through the Admin API or the Admin Portal.
- Your server grants an Access Manager token to the client app.
- The client app sends an authorized request, and DataSync validates and stores the object.
- When the object changes, DataSync publishes a DataSync event (message type 5) that reaches the client app on the object's ID channel or a projection channel.
Core concepts
| Concept | What it is | Learn more |
|---|---|---|
| Entity | A stored object with a JSON payload | Data model |
| Relationship | A typed link between two entities | Data model |
| Class | A versioned type definition for entities or relationships | Schemas |
| Users, channels, memberships | Built-in classes PubNub seeds for you | Built-in types |
| Projection | A named view controlling which fields a token can read and write | Projections |
| DataSync event | A real-time change notification (message type 5) | Events |
What you can build
| Use case | What you can build |
|---|---|
| Live-shopping marketplaces | Model products, sellers, and viewers as entities and relationships, keeping stock and price changes flowing to every viewer in real time. |
| Multiplayer game state | Store object types for match state, players, and items, with payload fields validated per class. |
| IoT device registries | Track device entities with per-class time-to-live so stale devices expire automatically. |
| Collaborative app state | Share documents or boards as entities, and use field-level projections so different collaborators see or edit only the fields they are allowed to. |
Configuration
As of 2026-09-21, DataSync is available to new accounts and accounts that are not actively using App Context.
If your keysets use App Context, keep using it. App Context remains fully supported.
DataSync is configured per keyset, and must be enabled on the keyset before any request succeeds. Data lives in a single region you select when DataSync is enabled, and that region is locked afterwards. Access Manager must also be enabled on the keyset.
All DataSync requests are authorized by Access Manager. Refer to Access control and permissions management for how tokens and grants work, and DataSync access control for what DataSync adds on top.
Classes are managed with the Admin API and event rules in the Admin Portal. Events are off by default and enabled per class version. Events publish asynchronously. DataSync publishes each change event at least once, so a subscriber can receive the same event more than once. A subscriber receives them over the live subscribe path, so it can miss events while it's disconnected. Refer to How events relate to subscribe.
SDK support
DataSync is available in two PubNub SDKs:
| SDK | DataSync API | DataSync SDK entities |
|---|---|---|
| JavaScript | Yes | Yes |
| C# | Yes | No |
From any other language, call the Core REST API directly. It covers all five object kinds: DataSync (Entity), DataSync (Relationship), DataSync (User), DataSync (Channel), and DataSync (Membership).
DataSync SDK entities are per-object handles that build the data channel name and scope the subscription for you. The C# SDK has no DataSync SDK entities, so in C# you subscribe to the object's data channel with a Channel SDK entity and attach a DataSync listener to that Subscription, a SubscriptionSet, or the PubNub client. Both SDKs receive the same events either way.
DataSync vs App Context
DataSync is the successor to App Context. Both manage users, channels, and memberships, but DataSync generalizes them into versioned classes over entities and relationships.
| Aspect | App Context | DataSync |
|---|---|---|
| Object types | Fixed to users, channels, memberships | Arbitrary entity and relationship classes, including users, channels, and memberships |
| Schemas | Not enforced | Typed property declarations per class version, validated on write |
| Partial updates | Limited | JSON Patch with ETags for optimistic concurrency |
| Field-level access | Not available | Projections control read and write access per field |
| Expiry | Not available | Per-class time-to-live |
| Search | Single tier | filter_fast (strongly consistent) and filter (eventually consistent) |
| Pagination | Page tokens | Cursor-based |
| Event message type | 2 | 5 |
| Access Manager | Optional | Required |