Checkpoints & Rewind
All actors in Hantera automatically maintain checkpoints of their state. These checkpoints can be used to view historical states or restore an actor to a previous point in time. This functionality is available on all actor types including Order, Payment, Ticket, Asset, and SKU.
What are Checkpoints?
Every time commands are applied to an actor, a mutation set is created and persisted. Each mutation set represents a checkpoint containing:
- Checkpoint ID: A unique UUID identifier
- Timestamp: When the mutation set was created
- Metadata: Optional information about the changes (e.g., which commands were applied)
These mutation sets form a complete history of all changes made to the actor over time. By replaying mutations up to a specific checkpoint, the system can reconstruct the exact state of the actor at that point in time.
Viewing Available Checkpoints
Use the getCheckpoints message to retrieve all available checkpoints for an actor:
POST https://<hantera-hostname>/resources/actors/order/ec806cf5-d976-49de-b390-03b303da8117Authorization: Bearer <YOUR TOKEN>Content-Type: application/json
[{ "type": "getCheckpoints", "body": {}}]curl -i -X POST \ https://<hantera-hostname>/resources/actors/order/ec806cf5-d976-49de-b390-03b303da8117 \ -H 'Authorization: Bearer <YOUR TOKEN>' \ -H 'Content-Type: application/json' \ -d '[{ "type": "getCheckpoints", "body": {}}]'Invoke-WebRequest `-Uri "https://<hantera-hostname>/resources/actors/order/ec806cf5-d976-49de-b390-03b303da8117" `-Method POST `-Headers @{Authorization="Bearer <YOUR TOKEN>"; 'Content-Type'="application/json"} `-Body '[{ "type": "getCheckpoints", "body": {}}]'Response:
[ { "checkpointId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "timestamp": "2025-01-15T10:30:00Z", "metadata": {} }, { "checkpointId": "b2c3d4e5-f6a7-8901-bcde-f12345678901", "timestamp": "2025-01-15T14:45:00Z", "metadata": { "commands": [{"type": "addTag", "key": "priority"}] } }]Checkpoints are returned in chronological order, from earliest to most recent.
Rewinding to a Checkpoint
The rewind message restores an actor to the state it had at a specific checkpoint.
POST https://<hantera-hostname>/resources/actors/order/ec806cf5-d976-49de-b390-03b303da8117Authorization: Bearer <YOUR TOKEN>Content-Type: application/json
[{ "type": "rewind", "body": { "checkpointId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" }}]curl -i -X POST \ https://<hantera-hostname>/resources/actors/order/ec806cf5-d976-49de-b390-03b303da8117 \ -H 'Authorization: Bearer <YOUR TOKEN>' \ -H 'Content-Type: application/json' \ -d '[{ "type": "rewind", "body": { "checkpointId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" }}]'Invoke-WebRequest `-Uri "https://<hantera-hostname>/resources/actors/order/ec806cf5-d976-49de-b390-03b303da8117" `-Method POST `-Headers @{Authorization="Bearer <YOUR TOKEN>"; 'Content-Type'="application/json"} `-Body '[{ "type": "rewind", "body": { "checkpointId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" }}]'Response:
{ "success": true, "checkpointId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "timestamp": "2025-01-15T10:30:00Z", "checkpointsAffected": 1}How Rewind Works
Rewind is a non-destructive operation:
- The system finds the target checkpoint in the mutation history
- It rebuilds the state by replaying all mutations up to that checkpoint
- It calculates the difference between the current state and the checkpoint state
- A new mutation set is appended that transforms the current state to match the checkpoint state
- An activity log entry is added recording the rewind operation
The original mutation history is preserved, and the rewind itself becomes a new checkpoint in the history. This means you can even rewind a rewind if needed.
Activity Log Preservation
When rewinding, activity logs are preserved. A new entry is automatically added to document the rewind:
"Rewound order to checkpoint at {timestamp}"This ensures full traceability of state changes.
Previewing Old States
You can preview what an actor’s state looked like at a previous checkpoint without actually performing a rewind. This is done by combining the rewind message with preview mode:
POST https://<hantera-hostname>/resources/actors/order/ec806cf5-d976-49de-b390-03b303da8117?previewAuthorization: Bearer <YOUR TOKEN>Content-Type: application/json
[{ "type": "rewind", "body": { "checkpointId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" }},{ "type": "query", "body": { "query": { "fields": ["orderId", "orderNumber", "orderState", "total"], "navigate: [{ "edge": "deliveries", "node": { "fields": ["deliveryId", "deliveryState"] } }] } }}]curl -i -X POST \ https://<hantera-hostname>/resources/actors/order/ec806cf5-d976-49de-b390-03b303da8117?preview \ -H 'Authorization: Bearer <YOUR TOKEN>' \ -H 'Content-Type: application/json' \ -d '[{ "type": "rewind", "body": { "checkpointId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" }},{ "type": "query", "body": { "query": { "fields": ["orderId", "orderNumber", "orderState", "total"], "navigate: [{ "edge": "deliveries", "node": { "fields": ["deliveryId", "deliveryState"] } }] } }}]'Invoke-WebRequest `-Uri "https://<hantera-hostname>/resources/actors/order/ec806cf5-d976-49de-b390-03b303da8117?preview" `-Method POST `-Headers @{Authorization="Bearer <YOUR TOKEN>"; 'Content-Type'="application/json"} `-Body '[{ "type": "rewind", "body": { "checkpointId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" }},{ "type": "query", "body": { "query": { "fields": ["orderId", "orderNumber", "orderState", "total"], "navigate: [{ "edge": "deliveries", "node": { "fields": ["deliveryId", "deliveryState"] } }] } }}]'In preview mode:
- The rewind is performed in an isolated transaction
- Subsequent messages (like
query) see the rewound state - All changes are automatically rolled back at the end
- No data is persisted
This is useful for:
- Debugging issues by inspecting historical state
- Auditing changes over time
- Comparing current state with previous states
- Customer support scenarios where you need to understand what happened
Access Control
Rewind operations require specific permissions:
| Permission | Description |
|---|---|
actors/<type>:rewind | Full rewind permission. Allows actual rewind operations that persist state changes. |
actors/<type>:rewind:preview | Preview-only permission. Allows rewinding in preview mode to view historical states, but changes are not persisted. |
For example:
actors/order:rewind- Can rewind ordersactors/ticket:rewind:preview- Can only preview historical ticket states
The preview permission is useful for support personnel or auditors who need to investigate historical states without the ability to modify data.
Use Cases
Reverting Mistakes
If incorrect commands were applied to an actor, you can rewind to a checkpoint before those changes:
- Call
getCheckpointsto find the appropriate checkpoint - Call
rewindwith the checkpoint ID - The actor returns to its previous state
Auditing and Debugging
Use preview mode to investigate what an actor looked like at any point in time:
- Call
getCheckpointsto see the history - Use
rewindwith?previewto view the historical state - Query the state to inspect specific fields
Comparing States
You can compare an actor’s current state with a historical state:
- Query the current state
- In preview mode, rewind and query the historical state
- Compare the two results
Related Messages
getCheckpoints- Returns available checkpoints for an actorrewind- Rewinds an actor to a specific checkpoint