What are some strategies for versioning non-text based files?
Assistant
Versioning non-text files presents challenges that you don't encounter with text-based files. While text-based files can be version-controlled through standard tools like Git, which provides line-by-line diffing, non-text files require specialized approaches. Here are some strategies to consider:
Binary Diffs
Store Diffs, Not Files: Use tools that specialize in binary diffs to store changes rather than complete file versions. Some version control systems like Git-LFS (Git Large File Storage) or SVN can handle binary diffs efficiently.
Delta Encoding: Implement delta encoding, where you only store the changes between versions rather than the complete files. This reduces the storage requirements but complicates the retrieval process.
External Version Control Systems
Dedicated Systems: Some industries have specialized version control systems designed for their needs. For instance, SolidWorks PDM for CAD files or Perforce Helix Core for multimedia assets.
Database Storage: Store binary data in databases designed for version control. This makes it easier to keep track of revisions and can be especially useful for larger teams.
Metadata Tagging
Version Metadata: Attach metadata to the binary files to indicate version numbers, changes made, and who made the changes. This makes it easier to roll back to previous versions and understand the history of the file.
Timestamps: Automatically append timestamps to file names or metadata to track changes over time.
Hashing
Checksums: Compute and store hash values (MD5, SHA-1, etc.) for each version of the file. If the file changes, the hash will change, signaling that a new version exists. This is useful for quick comparisons but won't help in identifying what specifically changed.
Decoupling
Data vs. Metadata: Store the non-text data and metadata separately but link them logically. This allows you to version-control the metadata, which in turn describes the versioning for the binary data.
Artifactory Repositories
Use Artifact Repositories: Tools like JFrog Artifactory or Nexus Repository Manager can manage binary artifacts and their versions efficiently.
File Locking
Exclusive Locks: In a multi-user environment, implement a check-out/check-in system to prevent conflicts. Users must lock a file to edit it, thereby avoiding simultaneous edits that can't be merged.
Format Conversion
Convert to Text: Where possible, convert binary files to a text-based format for versioning. For example, some 3D models can be represented in plain text formats.
Visual Diffs
Specialized Diff Tools: Use tools that provide visual diffing for specific binary file types (e.g., image diffing tools for images, or specialized tools for database files).
As you're more interested in technical details, it would be beneficial to consider integrating these approaches into your CI/CD pipeline for automation and to ensure consistent versioning practices across your team or organization.
User
Tell me more about dedicated versioning systems.
Assistant
Certainly! Dedicated version control systems for non-text files are specialized solutions designed to handle the unique challenges posed by binary or complex data types like multimedia files, 3D models, databases, etc. These systems often offer advanced features tailored to specific industries or file types. Here's a deeper dive:
Industry-Specific Systems
CAD Version Control: For engineering designs like AutoCAD or SolidWorks files, systems like SolidWorks PDM or Autodesk Vault are often used. They not only manage versions but also handle relations between files (like assemblies and parts).
Multimedia Versioning: Perforce Helix Core is popular in the gaming and multimedia industry. It's optimized for large binary assets like textures, sound files, and video. Perforce can also handle large codebases and offers atomic commits.
Medical Records: In healthcare, versioning of medical images and patient records has to be both secure and efficient. Systems for this often need to comply with regulations like HIPAA. They may employ cryptographic techniques for secure versioning.
Features
File Locking: Many of these systems use a locking mechanism to prevent conflicts from arising when multiple users try to edit the same file.
Branching and Merging: Some dedicated systems offer advanced branching and merging options specifically tailored to their file types. For example, branching a 3D model to try out different design modifications.
Metadata Management: These systems often provide elaborate ways to manage metadata, making it easier to track changes, understand file history, and roll back to previous versions.
Access Control and Audit Trails: In addition to basic versioning, these systems often include robust access controls and comprehensive audit trails, which are essential for regulated industries.
Asset Management: Many of these systems go beyond version control to offer full-fledged asset management. This can include features like automated build systems, dependency resolution, and more.
Delta Encoding & Binary Diffs: Advanced systems can efficiently store and serve up only the changes between two binary file versions, rather than storing each version in its entirety.
Visualization: Some systems offer visualization tools that allow you to preview changes between different versions of a file directly within the version control system.
User
What are the core concepts I need to consider when making a change tracking system? I am building change tracking for objects and annotations (for the purpose of building deep learning datasets).
Assistant
Building a change tracking system for objects and annotations in deep learning datasets is a complex task that requires careful consideration of several core concepts. Given your background as an expert programmer interested in technical details, here are some nuanced points to consider:
Data Structure and Storage
Immutable Objects: Consider using immutability for stored objects and annotations. Once an object is created, it should not be changed; instead, a new version should be created. This aids in robust change tracking.
Database Schema: Design your database schema to efficiently store version information. You might consider relational databases for strong ACID compliance or NoSQL databases for flexibility, depending on your needs.
File Format: Decide on a format for storing annotations and object data that allows for easy versioning. Formats like JSON or XML can be useful for text-based annotations, while binary formats might be more suitable for image or audio data.
Versioning Strategy
Incremental Versioning: Implement incremental version numbers or hashes to identify each change. You may also employ semantic versioning for more context.
Change Lists: Keep a list of changes (diffs) rather than complete versions to minimize storage requirements. Delta encoding techniques can be useful here.
Branching and Merging: Allow for branching of annotation sets to facilitate concurrent work, and create a mechanism to merge these branches efficiently.
Change Metadata
Audit Trail: Each change should come with metadata indicating what was changed, who made the change, and when the change was made.
Change Classification: Since this is for deep learning, you might also need to classify the types of changes (e.g., "object added," "annotation refined").
Commenting: Enable annotators to comment on why a particular change was made, providing context for future reference.
User Interface
Interactive UI: An intuitive and responsive user interface can facilitate the annotation process and make tracking changes easier. Consider features like undo/redo, visual diffs, and change previews.
Conflict Resolution: Build UI mechanisms for resolving conflicts when merging branches or accepting changes from multiple annotators.
User
Nice, I think I have considered a lot of these points already. For immutable objects, when I increment a version, should that version override the old one or allow it to exist alongside?
Assistant
Great to hear that you've already considered many of these core concepts. When it comes to immutability and versioning, whether to override the old version or allow it to exist alongside the new version depends on various factors related to your specific use case.
Keep Both Versions (Immutability)
Audit Trail: Keeping both versions intact provides a complete history of changes, which can be crucial for auditing or for tracing the evolution of your dataset.
Rollback: If an error is made in a new version, you can easily revert to a previous version.
Concurrent Versions: Multiple versions can co-exist, which may be useful if different teams or processes depend on different versions of the object or annotation.
Change Analysis: Having all versions allows you to analyze how your dataset has evolved over time, which can provide valuable insights, especially in the context of deep learning where data drift could be a concern.
Storage Cost: The major downside is the increased storage requirement, as each version needs to be stored separately.
Override Old Version
Storage Efficiency: Overriding the old version with the new one is more storage-efficient, especially if you're dealing with large binary files or a high rate of changes.
Simplicity: This approach simplifies the data model as you only need to keep track of the current version.
Consistency: There's no risk of different processes accidentally using different versions of the same object or annotation, ensuring that everyone is always working with the latest data.
Limited History: This method loses the historical state of each object, so you can't roll back or audit changes.
Hybrid Approach
You could also consider a hybrid approach:
Keep N Most Recent: Store only the last N versions of each object, providing a compromise between history and storage efficiency.
Archiving: Old versions could be moved to cheaper, slower storage after a certain period or after they have been superseded by a certain number of newer versions.
Diffs Instead of Full Versions: Store the initial state and the diffs to recreate any version, thereby reducing storage cost while maintaining full history.
Given your technical background, you might also consider a programmatically enforceable retention policy for the older versions. Such a policy can be encoded into your system logic to automate the decision-making process around version retention based on criteria like age, usage, or relevance to current models.
User
What is delta encoding?
Assistant
Delta encoding is a method used to store or transmit data in the form of differences (deltas) between sequential or related data rather than complete files. More generally this is known as data differencing. Delta encoding is sometimes called delta compression, particularly where archival histories of changes are required.
Here's a more technical dive into the subject:
How Delta Encoding Works
Initial Version: The original (or "base") version of the data is stored in its entirety.
Subsequent Versions: Instead of storing complete versions of the object for each change, you only store the differences between the new version and its base or immediate predecessor.
Reconstruction: To recreate a particular version, you start with the initial version and apply each of the deltas in sequence.
Types of Delta Encoding
File-level: Here, the deltas are computed for the entire file, often as a binary diff. This is common in version control systems for binary files.
Block-level: In this approach, files are divided into blocks, and deltas are computed for each block. This is often used in backup systems.
Byte-level: This is a more granular form of delta encoding and involves finding the smallest change at the byte level.
Algorithms and Techniques
Longest Common Subsequence (LCS): This algorithm is often used to find the longest sequence common to the base version and the modified version to compute a minimal delta.
Rsync Algorithm: This is commonly used for block-level delta encoding and is optimized for performance.
VDelta: This algorithm minimizes the amount of memory required to compute a delta and is used in applications where memory use is a concern.
Use Cases
Version Control: Especially useful for binary files where line-by-line diffs are not applicable.
Backup Systems: Only the changes made since the last backup are stored, saving storage space.
Network Transmission: Used in optimizing data transfers over networks by only sending the changes between versions of files.
Real-time Collaboration: In applications like Google Docs, delta encoding can be used to sync changes across multiple users efficiently.
User
I don't think the objects in the dataset will change very much, so I'm not too worried about space efficiency. For example, you take a picture, you don't go back and edit that picture much once it is in the dataset.
Assistant
In that case, the requirement for storage efficiency through techniques like delta encoding may be less of a concern for you. Given that the objects in your dataset are relatively static once created, a simpler versioning scheme might suffice. You could opt for a strategy that stores each version in its entirety, focusing on immutability to maintain a reliable history of changes.
The advantage of this approach is simplicity and robustness. You will always have a complete snapshot of the dataset at each version, making it easier to audit changes, revert to prior versions, or even fork the dataset for different experimental conditions. The full-version storage also makes it easier to parallelize reads for each version, as no reconstruction from deltas is required.
Since you're not overly concerned with storage, you can prioritize other aspects such as:
Auditability: Each immutable version provides a clear history or audit trail.
Ease of Access: Complete versions are easier and faster to access because they don't require assembly from a base version and a series of deltas.
Isolation: If different versions are needed for different experiments or phases of a project, each version exists as its own complete entity and can be used without affecting others.
Data Integrity: Full snapshots of the data reduce the risk of errors in version reconstruction, particularly beneficial in applications like deep learning where data quality is paramount.
Given your technical background, implementing such a system should be straightforward. Depending on your specific needs, you might also consider features like metadata tagging for version snapshots, enabling more detailed queries and easier navigation through the version history.
User
I have been using a concept I've been calling deltas. When a change is made to an annotation then I create a structure called a delta with an action "create" or "delete". This allows moderators to go through and approve or reject actions. I don't have "update" because that could be captured by incrementing a version number and the new annotation would have a "create" delta.
Assistant
Your approach of using "deltas" with "create" and "delete" actions is an interesting design choice, especially for managing annotations in a dataset. This strategy appears to align well with the concept of Command Sourcing, where changes are stored as a sequence of actions (or commands) that can be replayed to reconstruct the state of a system.
Advantages:
Auditability: Every action is logged, creating a robust history for auditing or debugging purposes.
Moderation: Since each delta represents a discrete action, it becomes straightforward for moderators to approve or reject individual changes.
Simplicity: By breaking down changes into elementary "create" and "delete" actions, you can avoid the complexity of managing updates as a unique type of change.
Immutability: Your design intrinsically supports the idea of immutable versions of annotations, allowing you to recreate any state by applying the sequence of approved deltas.
Traceability: This approach makes it easy to correlate changes to specific actions and users, providing clear accountability.
Things to Consider:
Indexing and Querying: Depending on how many deltas you accumulate, you might need efficient ways to query them. Database indexing or even specialized search engines could be helpful.
Batch Operations: If a series of related changes are to be made, consider how to group these into a single batch operation that can be approved or rejected as a unit.
Concurrency: Make sure to implement mechanisms to handle concurrency issues, especially if multiple users can create deltas simultaneously.
State Reconstruction: While this approach allows for easy state reconstruction, consider the performance implications if you need to replay a long sequence of deltas.
UI/UX: Think about how to present these deltas to the moderators in an intuitive way. Filtering, sorting, and grouping functionalities may enhance their experience.
Retention Policy: Over time, the delta history could grow large. Even if storage is not an immediate concern, you might still need a policy for archiving or purging old deltas.
Data Validation: Ensure that the system validates deltas for consistency and integrity, especially since a "create" or "delete" could lead to an inconsistent state if not managed carefully.
User
I have been using this for annotations and a different system for objects. Could the same concept apply to objects (files)?
Assistant
Absolutely, the concept of using "deltas" with "create" and "delete" actions can be extended to manage objects or files as well. Your approach lends itself to a generic, event-driven model that can be applied to different types of entities, be they annotations or binary files like images, audio, or other data types. Here are some considerations when extending this approach to objects:
Adaptations for Files:
File Metadata: If you're dealing with files, you may also want to include additional metadata in your delta structure, such as file type, size, or hash for integrity checks.
Chunks and Blocks: For large files, consider breaking them into chunks or blocks. This way, your deltas could target specific parts of a file, potentially optimizing storage and data manipulation operations.
Composite Actions: You might find that certain operations naturally occur together (e.g., deleting an object and its associated annotations). In these cases, you might use a composite delta that encapsulates multiple actions.
Commonalities Across Systems:
Unified Moderation: If both annotations and objects are subject to moderation, a unified delta system would streamline the moderation process.
Reusability: Common logic for generating, storing, and applying deltas can be shared across both annotations and objects, promoting code reusability.
Consistency: A uniform approach ensures that the system behavior remains consistent, regardless of the entity type being managed.
Technical Challenges:
Concurrency: Managing concurrency becomes more complex as you add more types of entities that can be changed. You'll need to ensure that the system can handle simultaneous changes to objects and annotations coherently.
Performance: The efficiency of applying deltas to reconstruct state could vary between text-based annotations and binary files. Optimizations might be needed for each case.
Data Integrity: With more entity types, there's an increased risk of ending up in inconsistent states. Robust validation becomes even more crucial.
Storage: Even though you're not particularly concerned about storage, some considerations might still apply, especially for large files.
Given your expertise in programming and interest in technical intricacies, extending the delta concept across different types of entities could offer a satisfying design challenge. It could also streamline your system architecture, making it more extensible and easier to maintain in the long term.
User
Is Command Sourcing a real concept?
Assistant
Apologies for the confusion. The term I should have referred to is "Event Sourcing," not "Command Sourcing." Event Sourcing is the architectural pattern where changes to the application state are stored as a sequence of events. These events can then be replayed to recreate the application's state at any point in time.
In Event Sourcing:
Events Are Immutable: Once an event is stored, it's never modified. New events are appended to the event store.
Event Replay: The system can rebuild any state by replaying the sequence of stored events.
Event Store: A specialized form of storage is often used to keep events in a sequence, optimized for appending new events and replaying existing ones.
CQRS: Event Sourcing is often combined with the Command Query Responsibility Segregation (CQRS) pattern, where the write operations (commands) are separated from read operations (queries), although they are not required to be used together.
In your case, the concept of storing "deltas" with "create" and "delete" actions is closely aligned with Event Sourcing. Each delta could be considered an event that captures a state change. This allows you to rebuild the state of an annotation or object by replaying the relevant sequence of deltas (events), and it also enables auditing, debugging, and more.
Again, apologies for the earlier mistake. Thanks for catching that. Would you like to know more details about Event Sourcing?
User
Yes.
Assistant
Certainly! Event Sourcing is an architectural pattern that's often used in complex systems where state changes need to be captured, recorded, and possibly replayed. Here's a deep dive into the concept:
Core Concepts of Event Sourcing
Immutable Events: Every change to the state of an application is captured as an immutable "event." Once written, an event is never updated or deleted.
Event Store: Events are stored in an ordered log known as an "Event Store," often optimized for append-only operations and high-throughput reads.
State Reconstruction: To determine the current state of an entity, events are replayed from the event store. This can be from the beginning of time or from a specific snapshot.
Event Handlers: These are the logic units responsible for handling each event type and applying changes to the application state.
Snapshots: To speed up state reconstruction, snapshots of an entity's state can be taken at regular intervals. These act as checkpoints.
Versioning: Events often require versioning to accommodate changes in an evolving system.
Advantages
Auditability: A complete and immutable log of all state changes allows for strong auditing capabilities.
Debugging: The ability to replay events can be extremely helpful in debugging issues.
Flexibility: As requirements evolve, you can adapt your system more easily. New views can be generated by replaying the existing events.
Scalability: Event Sourcing can scale horizontally, especially when used in conjunction with CQRS.
Challenges
Complexity: Implementing Event Sourcing can be complex and may introduce new challenges such as event versioning and schema evolution.
Performance: Replaying many events can be time-consuming. The use of snapshots can mitigate this to some extent.
Data Volume: Storing every state change can result in large amounts of data. This isn't always an issue, but it can be in high-throughput systems.
Consistency: In distributed systems, ensuring the ordered delivery of events can be challenging.
Common Use-Cases
User
Does event sourcing lend itself well to a version control system? Branching and merging seem like they would be a challenge.
Assistant
Event Sourcing and version control systems (VCS) both deal with tracking changes over time, but they are optimized for different types of challenges. While Event Sourcing excels at capturing every state change in an application, traditional VCSs like Git are designed for collaborative editing of text-based files. They include specialized features for branching, merging, and conflict resolution.
Challenges with Event Sourcing in a VCS Context
Branching: In a typical Event Sourcing system, events are usually linear and global. Implementing branching would require a more complex mechanism to manage multiple event streams or branches, which is non-trivial.
Merging: The problem extends to merging as well. While text-based VCSs have sophisticated algorithms for merging changes, merging divergent event streams would require domain-specific logic to reconcile conflicting state changes.
Conflict Resolution: Event Sourcing systems often lack native support for conflict resolution, which is a cornerstone feature in a VCS.
Possible Solutions
Explicit Branching Events: Introduce special branching and merging events that signify a divergence or convergence of event streams. This would be complex to manage and require careful design.
Domain-Specific Merging Logic: Implement custom logic to handle the merging of event streams in a way that makes sense for the specific application domain.
Optimistic Concurrency Control: Use version numbers or timestamps to detect conflicts, with subsequent resolution steps.
Event Transformation: Transform events in one branch so they can be applied to another branch. This is akin to "rebasing" in Git but could be very complex depending on the application domain.
Hybrid Approach
Another possible approach is to use Event Sourcing in conjunction with a VCS:
Store Events in VCS: Serialize the events and store them in a traditional VCS. This allows you to leverage the branching and merging capabilities of the VCS for your event streams.
Branching Metadata: Use metadata to mark branching and merging points within your event stream, much like Git tags.
Given your technical expertise, implementing such a hybrid system or dealing with the intricacies of branching and merging within pure Event Sourcing would undoubtedly be a challenging yet rewarding endeavor. It would involve tackling some of the most difficult problems in both Event Sourcing and version control systems.
User
What is event sourcing most frequently used for?
Assistant
Event Sourcing is commonly used in systems where the history of state changes is important, and the ability to reconstruct past states or trace the sequence of state changes is beneficial. Here are some typical use-cases:
Financial Systems
Accounting and Banking: Every financial transaction is an event that changes an account's state. Using Event Sourcing, an account's state can be reconstructed at any point, which is often a legal requirement.
Trading Systems: In stock or commodity trading, understanding the sequence of trades and their impact is crucial. Event Sourcing can be a natural fit for these applications.
E-Commerce
Order Management: From order creation to payment processing and shipping, each step can be modeled as an event. This approach simplifies complex workflows and allows for easier debugging and auditing.
Inventory Systems: Changes in stock levels, pricing, or product attributes can be events, making it easier to track how the state of the inventory changes over time.
Customer Relationship Management (CRM)
Customer Interactions: Every interaction with a customer or a change in customer status can be recorded as an event, providing a complete history of the customer's journey.
Ticketing Systems: Support tickets often go through various state changes (e.g., open, pending, closed), and Event Sourcing can capture this workflow.
Internet of Things (IoT)
Sensor Data: Readings from sensors can be stored as events, which can then be analyzed for trends or anomalies.
Device State: The state changes of an IoT device can be modeled as events, making it easier to understand its behavior over time.
Real-Time Analytics and Monitoring
Clickstream Analytics: User interactions on a website can be modeled as a series of events, useful for real-time analytics.
System Monitoring: In a microservices architecture, Event Sourcing can be used to track changes in each service's state for real-time monitoring and post-incident analysis.
Collaborative Software
Document Editing: For applications like Google Docs, each edit could be an event, allowing for real-time collaboration and the ability to roll back changes.
User
Are these typically centralized services?
Assistant
Event Sourcing systems can be either centralized or distributed, depending on the architectural requirements, scalability needs, and the specific use case.
Centralized Systems
Single Event Store: In a centralized system, all events are stored in a single event store, making it easier to maintain consistency and order of events.
Simplified Management: Centralized systems are easier to manage, monitor, and backup, since all data resides in a single location.
Lower Latency: Being centralized can also reduce the latency involved in reading and appending events to the store.
Audit and Compliance: Centralized systems can simplify regulatory compliance by consolidating all state-changing events into one place.
Examples: Small-to-medium scale financial systems, CRMs, and internal applications might use a centralized approach.
Distributed Systems
Horizontal Scalability: Distributed systems can handle a higher volume of events and are better suited for microservices architectures or cloud-native applications.
Fault Tolerance: Data can be replicated across multiple nodes, increasing the system's resilience to hardware failures.
Geo-Distribution: For global applications, having distributed event stores closer to the user can reduce latency.
Complexity: Handling event ordering, consistency, and conflict resolution becomes more challenging in a distributed setup.
Examples: Large-scale e-commerce platforms, real-time analytics systems, and global IoT platforms often require a distributed architecture.
Hybrid Approaches
Multi-Tenancy: A centralized event store might serve multiple services or bounded contexts within an organization, achieving a form of logical distribution.
Sharding and Partitioning: Even within a "centralized" event store, data can be sharded or partitioned for better performance, introducing elements of distribution.
CQRS: Combined with Event Sourcing, Command Query Responsibility Segregation (CQRS) can be implemented in either centralized or distributed manners depending on the scenario.
Given your background in software engineering, the choice between centralized and distributed architectures would involve trade-offs in terms of complexity, scalability, and management overhead. The right choice would depend on the specific requirements of the system you're building or working with.
User
What is an example of a distributed event sourcing system?
Assistant
A distributed event sourcing system is often built around a high-throughput, scalable, and fault-tolerant message broker or data streaming platform. One popular example is a system built on Apache Kafka.
Example: E-commerce Platform Using Apache Kafka
Architecture
Services: Multiple microservices handle various aspects of the e-commerce platform, such as inventory management, order processing, payment, and customer interactions.
Event Store: Apache Kafka serves as the distributed event store. Each topic in Kafka could correspond to a different type of event or bounded context.
Producers: Microservices publish events to Kafka topics whenever a state change occurs, like a new order being placed or an inventory item being updated.
Consumers: Other microservices or external systems subscribe to these topics to react to changes, update their own state, or trigger additional workflows.
Replication: Kafka topics are replicated across multiple brokers to ensure fault tolerance and high availability.
Features
Scalability: Kafka can handle a large volume of events, allowing the e-commerce platform to scale horizontally as needed.
Ordering: Within each partition of a Kafka topic, events are strictly ordered, making it easier to reconstruct the state of an entity.
Fault Tolerance: Even if one or more Kafka brokers go down, the system can continue to function, thanks to the distributed nature of Kafka.
Geo-Distribution: For global operations, Kafka can be set up in a geo-replicated manner, ensuring low latency for users around the world.
Challenges
Complexity: Managing a distributed system, especially one based on microservices and Kafka, adds operational complexity.
Consistency: Ensuring global order and consistency across multiple Kafka topics or services can be challenging and might require additional mechanisms like distributed transactions or sagas.
Event Schema Management: With multiple services producing and consuming events, managing event schemas and ensuring backward and forward compatibility becomes critical.
Given your expertise in technical details and system design, understanding the inner workings of a distributed event sourcing system like this could offer you valuable insights into building robust, scalable applications.
User
Above you listed examples like ticketing systems, sensor data in IoT, document editing, game state, etc. These all seem like applications that would go to a central source. Are there any examples of ones that are distributed and then become merged?
Assistant
Certainly, some scenarios require a decentralized approach where event sourcing is performed at the "edges" of the system before being merged into a central or distributed store. This can be useful in situations where connectivity to a central event store is intermittent, where local autonomy is required, or where edge processing is beneficial for performance. Here are some examples:
Autonomous Vehicles
Edge Event Sourcing: Each vehicle generates events based on sensor data, user input, and system behavior. These are initially stored locally on the vehicle.
Central Merging: When the vehicle is within network reach or at scheduled intervals, these local events are merged into a central or distributed event store for broader analytics, system improvement, and compliance checks.
Mobile Applications
Offline Support: Mobile apps can generate and store events locally when the device is offline.
Syncing and Merging: Once back online, these events can be synced with a central event store, possibly using conflict resolution strategies if the same data might have been altered from other devices.
Remote Field Operations (Oil & Gas, Mining)
Local Event Stores: Due to connectivity issues, events related to machinery status, safety checks, etc., are initially stored at a local facility's systems.
Batch Upload: Periodically, this data is sent back to the central system for analytics, monitoring, and compliance checks.
Distributed Collaborative Software (e.g., Git)
Local Changes: Users make local changes and commit them as events in their local repository.
Merge and Conflict Resolution: When pushing to a remote repository, events are merged. Git's architecture allows for complex branching and merging strategies, including conflict resolution.
Edge Computing in IoT
Local Event Sourcing: Sensor data can be captured and initial processing done at the edge of the network, close to where the IoT devices are deployed.
Data Aggregation: The processed data may be sent to a central or distributed system where it's merged with data from other edge locations for further analysis or action.
Military Operations
Decentralized Command: Units operating in the field may have limited connectivity and need to make autonomous decisions, capturing events locally.
User
I want to use event sourcing. I have objects (files) and annotations. I want to support creating, deleting, and editing both of these. What would my events look like? Would I only have CREATE and DELETE? Edit could just be a CREATE of a new version...
Assistant
Given your interest in technical details, you're correct in identifying that events in an Event Sourcing system often focus on capturing state transitions. In your case, the objects (files) and annotations can have different events associated with their lifecycles. The granularity of these events largely depends on the kinds of operations you want to support and audit.
Here's a simple schema of what your events could look like:
For Objects (Files)
ObjectCreated: Triggered when a new object is created. It would include metadata such as the object ID, the initial version number, the file type, and possibly the user who created it.
AnnotationCreated: Triggered when a new annotation is created for an object.
json
{
"eventType": "AnnotationCreated",
"annotationId": "789",
"objectId": "123",
"content": "This is an annotation.",
"createdBy": "userA",
"timestamp": "2023-08-27T12:30:00Z"
}
AnnotationDeleted: Triggered when an annotation is deleted.
json
User
If I wanted to allow dataset owners to approve changes, should there be a separate approval event that references these events? I think it would be good to track who is approving what.
Assistant
Absolutely, adding approval events to your event sourcing model would be a good way to capture not just what changes were made, but also who approved them and when. This allows for greater accountability and auditability in the system. Given your focus on technical details, you'll appreciate that this also offers a way to reconstruct not just the state of the system, but also the decision-making process that led to that state.
Here's how you could structure approval events for both objects (files) and annotations:
Approval Events for Objects
ObjectChangeApproved: Triggered when a change to an object (either a creation of a new version or a deletion) has been approved.
AnnotationChangeApproved: Triggered when a change to an annotation (either a new annotation, a new version of an existing annotation, or a deletion) is approved.
Related Event: The relatedEvent field is used to reference the event that this approval event is related to. This allows you to keep track of which specific change was approved.
Versioning: Including version numbers in approval events allows you to have a history of what exactly was approved, supporting undo and historical querying functionalities.
Timestamp and Approver: These fields would help in auditing who approved what and when, adding accountability to your system.
Having these approval events enables you to reconstruct both the state and the approval history of your objects and annotations. This would be beneficial for scenarios where you need to audit changes, investigate issues, or understand the evolution of a dataset, all the while keeping track of the roles different users play in this evolution. Given your expertise in programming and systems, implementing this should offer an additional layer of control and traceability in your application.
User
Another way to do that would be to handle it externally, like a merge request on Github.
Assistant
Absolutely, handling the approval process externally, akin to GitHub's merge request or GitLab's merge request models, could also be an effective way to manage changes to objects and annotations in your dataset. This approach has its own set of advantages and challenges.
Advantages:
Separation of Concerns: The approval process is isolated from the core event-sourcing system, making each system simpler to manage and understand.
Flexibility: This external system can have its own rules, workflows, and UI, separate from the core application, giving you greater flexibility to adapt to different approval requirements.
Audit Trail: An external system can provide its own detailed history and auditing capabilities, such as comments on why a certain change was approved or rejected.
Multiple Reviewers: The model easily supports multiple rounds of review and multiple reviewers, including more complex workflows like requiring approvals from different parties.
Challenges:
Synchronization: You'll need to make sure that the external approval system and the core system are kept in sync. If an approval is granted externally, the corresponding change must be applied to the core system, and vice versa.
Complexity: Introducing an external system adds another layer of technology and process that must be maintained and understood. There may also be challenges around ensuring consistency and transactionality between the two systems.
User Experience: Navigating between two systems could potentially create a disjointed user experience, requiring extra effort in UI/UX design to make the transition seamless.
Given your focus on technical details, implementing this kind of external system would likely involve creating APIs or hooks that can notify your core system when a change has been approved in the external system. This way, you can apply the change in a controlled manner, potentially firing off an ObjectChangeApproved or AnnotationChangeApproved event internally once the external approval is received, to keep the history consistent.
This approach does add a level of complexity but also gives you more flexibility to design an approval workflow that can evolve independently of the core system.
User
It seems like there are two layers of consumers with event sourcing. Event validation must occur before the events are stored in the event log. Then there are consumers whose state is updated after events are added to the event log. So there is a special case consume that validates an incoming event with awareness of the state, has the event added to the event log, then updates state based on that event.
Assistant
You're absolutely correct, and this highlights a key aspect of the architecture in an event sourcing system. Events go through various stages, and there are different consumers at each stage with specific roles. Here's a breakdown considering your technical interest:
Validation Layer
Event Generation: Initially, an action or command in the system generates an event that represents a change. At this point, the event hasn't been stored yet.
Event Validation: Before the event is stored in the event log, it goes through a validation process. This process may involve checking the integrity of the event's data, the permissions of the user triggering the event, and even whether the event makes sense in the current state of the system. It's crucial to ensure that only valid events make it to the event log to maintain consistency and data integrity.
Event Storage: Once validated, the event is stored in the event log, making it immutable and part of the system's official history.
Consumption Layer
Stateful Consumers: After the event is stored, it is consumed by various consumers. These can be services, projections, or read models that maintain some state derived from the event log.
State Update: Each consumer updates its internal state based on the new event. This can involve simply appending the event to its own internal log, updating a read model, or triggering additional actions in the system.
Special Case: Validator as a Consumer
As you pointed out, the entity doing the validation could itself be considered a specialized kind of consumer, one that consumes the event before it's written to the log for the purpose of validation.
State-Aware Validation: In some cases, the validation logic needs to be aware of the system's current state. This is a bit of a chicken-and-egg problem because that state is generally built from the event log, which the new event hasn't been added to yet.
Optimistic Concurrency: One way to deal with this is through optimistic concurrency control. The validating consumer checks the current state, validates the event based on that state, and then attempts to write the event to the log. If the write is successful, great; if not (because another event changed the state in the meantime), the process can be retried.
Two-Phase Commit: Another option is using a two-phase commit or similar transactional mechanism to ensure that the event is validated and written atomically, ensuring consistency.
APIs and Integrations: Since many of these systems are designed for professional use in specific industries, they often offer APIs and integration capabilities to fit into existing workflows and systems.
Drawbacks
Cost: These systems are often more expensive than general-purpose version control systems.
Complexity: The advanced features and specialized nature of these systems can make them more complex to set up and maintain.
Vendor Lock-in: Being highly specialized, switching away from these systems can be a significant undertaking.
Since you have a strong technical background, you might find it interesting to explore how these dedicated systems work under the hood. They often use some advanced algorithms and data structures to optimize for the specific types of data they handle. You might also find their APIs useful for creating custom solutions that better fit into your existing workflows.
Access Control
Authentication and Authorization: Implement strong access controls to ensure that only authorized users can make changes.
Granular Permissions: Consider adding roles with varying levels of permissions, from read-only to full edit capabilities.
Performance Optimization
Caching: Implement caching mechanisms to improve performance, especially when dealing with large datasets.
Concurrency: Build your system to handle multiple users making concurrent changes, which may involve using optimistic or pessimistic locking mechanisms.
Quality Assurance
Validation Checks: Include checks to validate the integrity and consistency of the annotations. These could be automated tests or manual review steps.
Review Workflow: Establish a workflow that allows for peer review of changes, which is crucial for maintaining high-quality datasets.
Extensibility
APIs and Plugins: Design the system to be extensible so that you can add new features or integrate with other tools easily.
Export/Import: Make it easy to export the change history and annotations in standard formats so that they can be used with different systems or for reporting.
By taking these core concepts into account, you can build a robust change tracking system that not only serves the immediate requirements but is also scalable and extensible for future needs.
In summary, if your primary concern is auditing, rollback, or having a full history, then keeping both versions would be advantageous. If you are more concerned about storage efficiency and simplicity, then overriding might be more appropriate.
Advantages and Disadvantages
Advantages
Storage Efficiency: Drastically reduces storage requirements when multiple versions of files need to be stored.
Transmission Efficiency: Minimizes the amount of data to be sent over a network, thus saving bandwidth.
Disadvantages
Complexity: Delta encoding algorithms can be complex to implement.
Reconstruction Time: Depending on how many deltas need to be applied, reconstruction can take time, affecting performance.
Since you're interested in technical details, you might find it rewarding to study some of these algorithms more deeply, especially if you're considering their application in a system you're designing. Delta encoding can be highly effective for object and annotation versioning in deep learning datasets, especially if those datasets are large or change frequently.
Given your expertise in programming and interest in technical details, you might find it worthwhile to explore these aspects further. Your approach of using deltas aligns well with established patterns in software architecture and could serve as a strong foundation for your change tracking system.
Financial Systems: Every transaction is recorded, and the state of an account can be reconstructed at any point.
CRM Systems: Keeping track of every interaction and state change with a customer.
IoT Systems: Recording sensor readings as events allows for future analytics and state reconstruction.
Technical Considerations
Event Store Database: Specialized databases like EventStore, Kafka, or even traditional RDBMS can be used for the event store.
Event Schema: The schema of your events should be designed carefully to ensure they capture all necessary state change information.
Optimizations: Techniques like snapshotting or event compression can be implemented to optimize performance.
Given your interest in technical details and system design, you might find the Event Sourcing pattern highly applicable, especially when dealing with mutable entities like annotations and files. It offers a robust and scalable way to manage state changes over time.
Version Control: While not typically implemented using pure Event Sourcing, version control systems share some similarities, as they need to record each change to a codebase.
Gaming
Game State: In multiplayer online games, the state of the game can be managed through events, making it easier to sync states across distributed servers.
Regulatory Compliance
Audit Trails: For applications that require comprehensive auditing capabilities for compliance reasons, Event Sourcing provides an immutable history of all state changes.
Given the varied applicability across multiple domains, Event Sourcing is favored in scenarios requiring high auditability, complex business processes, real-time analytics, or a deep understanding of state changes over time.
Post-Mission Integration: After missions, data can be integrated back into the central command's event store for analysis, debriefing, and planning future missions.
In these examples, the event stores at the edge and at the central/distributed system may need to handle conflict resolution, data transformation, and versioning to successfully merge events. Given your background in software engineering, building or working with such distributed, eventually-consistent systems would likely present a challenging and rewarding set of problems to solve.
AnnotationVersionCreated: Triggered when an annotation is edited (again, as a new version).
json
{
"eventType": "AnnotationVersionCreated",
"annotationId": "789",
"version": 2,
"content": "This is an updated annotation.",
"createdBy": "userC",
"timestamp": "2023-08-27T14:30:00Z"
}
By using these events, you can reconstruct the state of any object or annotation at any point in time. If a new version is created for an edit, the system would inherently support an "undo" feature by reverting to a previous version. Depending on your application's needs, you might also add more events for additional state changes, like if an annotation is approved or an object is moved to a different category.
Given your background, implementing an Event Sourcing model like this could offer you a robust way to manage state transitions and maintain a detailed history for each object and annotation in your system.
Given your expertise in programming, you might appreciate that each of these steps can be complex in its own right, involving issues of transactionality, consistency, and scalability that need to be carefully managed to build a robust event sourcing system.