Version Control Features

ChronDB uniquely combines a document database with Git's powerful version control system, providing capabilities that traditional databases lack. This document explores the version control features of ChronDB and how they can be leveraged in your applications.

Version Control Overview

Unlike traditional databases that only store the current state of data, ChronDB automatically tracks the complete history of every document:

  • All changes are versioned: Every document update creates a new revision

  • Full history preservation: Historical states are never lost

  • Git foundation: Built on Git's proven version control infrastructure

  • First-class version management: Version control is a core feature, not an add-on

Document History and Revisions

Automatic Change Tracking

Every time a document is created, modified, or deleted, ChronDB:

  1. Creates a new version of the document

  2. Records metadata about the change (timestamp, author)

  3. Preserves the document's previous state

  4. Links the revisions in a chronological history

;; Create initial document
(chrondb/save db "user:1" {:name "John" :email "[email protected]"})

;; Update the document
(chrondb/save db "user:1" {:name "John" :email "[email protected]"})

;; Each operation creates a new version in the history

Accessing Document History

ChronDB provides API methods to access the complete history of any document:

ChronDB also provides low-level access to Git-based document history, allowing you to retrieve detailed commit information and document content at each version:

Retrieving Specific Document Versions

You can retrieve a document at a specific commit by providing the commit hash. Note that each retrieval operation generates a new commit to maintain chronological integrity:

Through other protocols, document history is also accessible:

REST API:

PostgreSQL Protocol:

Redis Protocol:

Point-in-Time Access

A key feature of ChronDB is the ability to access any document as it existed at a specific point in time:

This enables:

  • Historical reporting

  • Audit trails

  • Compliance requirements

  • Debugging and troubleshooting

  • "Time machine" capabilities for applications

Branching

ChronDB extends Git's branching model to document databases, allowing multiple parallel versions of your data to exist simultaneously.

Creating and Using Branches

Branch Use Cases

Branches enable powerful workflows:

  1. Development and Testing

    • Use branches to develop and test new features without affecting production data

    • Validate data migrations before applying to production

  2. What-If Analysis

    • Create branches to model different business scenarios

    • Run simulations with alternate data sets

  3. Multi-Tenancy

    • Use branches to isolate data for different tenants

    • Apply schema changes to specific tenants

  4. Feature Toggles

    • Implement unreleased features in separate branches

    • Merge when ready for production

  5. Temporary Workspaces

    • Create temporary branches for exploratory analysis

    • Discard when no longer needed

Branch Management

ChronDB provides APIs for managing branches:

Merging

ChronDB allows changes from one branch to be incorporated into another through merging.

Merge Operations

Merge Strategies

ChronDB supports different merge strategies:

  1. Fast-forward merge

    • Applied when the target branch hasn't changed since the source branch was created

    • Results in a linear history

  2. Recursive merge

    • Used when both branches have diverged

    • Combines changes from both branches

  3. Ours strategy

    • Prioritizes the target branch in conflict resolution

    • Useful when you want to override changes from the source branch

  4. Theirs strategy

    • Prioritizes the source branch in conflict resolution

    • Useful when you want to adopt all changes from the source branch

Conflict Resolution

When changes in different branches conflict, ChronDB provides tools for resolution:

Conflict Detection

ChronDB automatically detects conflicts during merge operations:

Conflict Resolution Strategies

  1. Manual Resolution

    • Identify conflicting fields

    • Choose the correct value for each conflict

    • Create a resolution commit

  2. Automatic Policy-Based Resolution

    • Define policies for automatic conflict resolution

    • Examples: "newest wins", "field-specific rules"

Comparing and Diffing

ChronDB provides powerful tools for comparing document versions:

This enables:

  • Visualizing changes over time

  • Understanding data evolution

  • Debugging unexpected changes

  • Audit and compliance reporting

Tagging and Snapshots

ChronDB allows you to tag specific points in your database's history:

Use cases for tagging:

  • Mark significant application releases

  • Create quarterly snapshots for reporting

  • Tag before major data migrations

  • Create recovery points

Auditing and Compliance

ChronDB's version control features naturally support auditing and compliance requirements:

Audit Trail

Every change in ChronDB is tracked with:

  • What changed (the data diff)

  • When it changed (timestamp)

  • Who changed it (committer information)

  • Why it changed (commit message)

Compliance Features

ChronDB helps meet regulatory requirements:

  • GDPR: Track all changes to personal data

  • HIPAA: Maintain comprehensive audit trails

  • SOX: Ensure financial data integrity and history

  • 21 CFR Part 11: Support for electronic records in regulated industries

Rollback and Reversion

ChronDB makes it easy to revert to previous states:

For git-based storage, you can also restore a document to a specific version by commit hash while preserving the complete history:

Unlike a traditional rollback that might discard history, this approach adds a new restoration commit that preserves the complete chronology of changes, ensuring full audit trails are maintained.

This enables:

  • Recovering from errors

  • Undoing problematic changes

  • Testing with real data then reverting

  • Maintaining a complete audit trail of all operations

Performance Considerations

Version control adds powerful capabilities but requires understanding some performance implications:

  1. Storage Growth

    • Historical versions increase storage requirements

    • Git's compression and deduplication help minimize impact

  2. Operation Overhead

    • Each write includes versioning overhead

    • Reading the latest version remains efficient

    • Historical queries have additional cost

  3. Optimization Strategies

    • Use git gc for repository optimization

    • Consider repository sharding for very large datasets

    • Use appropriate indexing for common queries

Best Practices

Commit Messages and Metadata

Add meaningful context to changes:

Branch Organization

Establish branch naming conventions:

  • feature/... for new features

  • fix/... for bug fixes

  • customer/... for customer-specific branches

Backup and Migration

Even though ChronDB preserves history, regular backups are recommended:

Conclusion

ChronDB's version control features provide unprecedented capabilities for tracking, managing, and leveraging data history. By combining the power of Git with a document database, ChronDB enables new workflows and solutions to problems that traditional databases can't easily address.

Whether you need audit trails for compliance, branches for development and testing, or time-travel for analysis, ChronDB's version control features offer a robust foundation for building temporally-aware applications.

Last updated