Event Sourcing Architecture
Workspace state is managed through an append-only event log. Each modification to a workspace generates an event that is appended to the log with an incrementing version number. The current state is reconstructed by replaying all events from the beginning (or from the latest snapshot).Benefits
- Complete History: Every change is recorded with timestamp and user information
- Conflict Resolution: Built-in optimistic locking with version-based conflict detection
- Undo/Redo: Natural support for time-travel and undo operations
- Collaboration: Multiple users can work simultaneously with automatic conflict handling
- Snapshots: Periodic snapshots optimize state reconstruction for workspaces with many events
Event Object
Unique identifier for the event (UUID)
Event type determining how the payload should be processed
Event-specific data containing the changes to apply
Unix timestamp (milliseconds) when the event was created
ID of the user who created the event
Name of the user who created the event
Sequential version number for optimistic locking
Event Types
WORKSPACE_CREATED
Initializes a new workspace with basic metadata.WORKSPACE_SNAPSHOT
Sets the complete workspace state in a single event. Used for workspace creation with initial content or for periodic snapshots.ITEM_CREATED
Creates a new item (canvas, text, flowchart, etc.) in the workspace.ITEM_UPDATED
Updates properties of an existing item.ITEM_DELETED
Removes an item from the workspace.Get Events
Retrieves all events for a workspace, optionally with the latest snapshot for efficient state reconstruction.Path Parameters
The workspace ID (UUID)
Response
Returns events after the latest snapshot (if one exists) and the snapshot itself.Array of events ordered by version
Current version number of the workspace (highest event version)
The response includes only events after the snapshot version. To reconstruct the full state, start with the snapshot state and apply all returned events in order.
Append Event
Appends a new event to the workspace event log with optimistic locking.Path Parameters
The workspace ID (UUID)
Request Body
The event to append
Unique event ID (UUID)
Event type (e.g., ITEM_CREATED, ITEM_UPDATED, ITEM_DELETED)
Event-specific payload
Unix timestamp in milliseconds
ID of the user creating the event
Name of the user creating the event
The version number the client is based on. Used for optimistic locking
Success Response
Returned when the event is successfully appended with no conflicts.Conflict Response
Returned when another event was appended sincebaseVersion. Client must merge changes and retry.
When a conflict occurs,
currentEvents contains all events that were appended since baseVersion. The client should:- Apply these events to their local state
- Re-generate their event based on the updated state
- Retry with the new
baseVersion(returned asversion)
Validation
The API automatically validates events to ensure data integrity:Name Uniqueness
When creating or renaming items, the API checks that no item with the same name and type exists in the same folder.Error Response
Version Conflicts
The API uses optimistic locking to prevent lost updates. Always include the current version asbaseVersion when appending events.
Snapshots
To optimize performance, ThinkEx automatically creates periodic snapshots of workspace state. Snapshots are created after a configurable number of events (default: every 100 events). Snapshots allow the API to return a base state without replaying thousands of events. The client only needs to apply events since the snapshot.Snapshot creation is automatic and asynchronous. It does not affect event append performance.