Time Travel Principles
Time Travel is Singdata Lakehouse's historical data access feature, allowing users to query data states at any point in time or recover deleted/modified data.
What is Time Travel
Time Travel is implemented based on the MVCC (Multi-Version Concurrency Control) mechanism. Every table in Lakehouse maintains multiple historical versions. Each data change (INSERT/UPDATE/DELETE/TRUNCATE) generates a new version, while older versions remain accessible.
How MVCC Works
Version Generation
Each time a transaction commits, Lakehouse generates a new table version:
| Operation | Version Change |
|---|---|
INSERT | New rows added, version number increments |
UPDATE | Old version marks rows as deleted, new version inserts them |
DELETE | Rows marked as deleted |
TRUNCATE | Entire table marked as a new version (empty) |
Version Query
Use the TIMESTAMP AS OF clause to query data at a specified point in time:
The system finds the most recent version before that point in time and returns a snapshot of that version's data.
Three Core Capabilities of Time Travel
1. Historical Data Query
Query data states at any past point in time, used for:
- Data comparison analysis (comparing changes at different points in time)
- Auditing and compliance (tracing historical data states)
- Troubleshooting (viewing data states before modification)
2. Data Recovery (UNDROP)
Recover deleted tables:
Scope: Regular tables, dynamic tables, materialized views, table streams
3. Data Rollback (RESTORE)
Roll back a table to a specified point in time:
Difference from UNDROP:
UNDROP: Recovers a dropped table (the table no longer exists)RESTORE: Rolls back data in an existing table (the table still exists, but data was modified/deleted by mistake)
Retention Period
The Time Travel retention period (data_retention_days) determines how long historical data remains accessible:
| Configuration | Description |
|---|---|
| Default value | 1 day (24 hours) |
| Value range | 0-90 days |
| Set to 0 | No historical versions are retained; Time Travel cannot be used |
| Beyond the period | Historical versions are physically deleted and cannot be recovered |
Storage Cost
Time Travel consumes additional storage space to preserve historical versions:
- Storage cost is proportional to data change frequency and retention period
- Tables that are frequently updated consume more storage under long retention periods
- It is recommended to set the retention period appropriately based on business needs
Usage Limitations
| Limitation | Description |
|---|---|
| Views not supported | Regular views do not store data and do not support Time Travel |
| External schemas not supported | Historical versions of external data sources are not managed by Lakehouse |
| Uncommitted real-time write data | Data written by RealtimeStream that has not been committed does not support Time Travel |
| Beyond retention period | Historical versions cannot be queried or recovered after physical deletion |
