Rolling upgrades in tellus: old code cannot learn a new shape
This deep dive explores the notoriously tricky problem of managing data schema changes during rolling upgrades in distributed systems. It showcases how the Rust-based tellus framework tackles this by implementing explicit schema versioning, upcasting, and downcasting, ensuring smooth transitions without data loss or corruption. For anyone building robust, continuously deployed services, this is a masterclass in practical distributed systems engineering.
The Lowdown
Rolling upgrades, a cornerstone of high-availability distributed systems, introduce a complex challenge: ensuring compatibility between old and new versions of an application as they run concurrently. The core issue arises when message types change, and older nodes, unaware of new fields or altered structures, struggle to interpret data from upgraded peers. This article delves into how the tellus framework, written in Rust, provides a robust solution to this dilemma.
- The Problem: During a rolling upgrade, old and new nodes co-exist, exchanging messages. If a message's schema changes (e.g., adding a field), an old node might fail to decode a new message, or worse, decode it incorrectly if using a compact serialization format like
postcardwhich lacks field names. - The
tellusSolution: The framework introduces aSchematrait, requiring every type transmitted across nodes to implement it. This trait includes aVERSIONconstant andencode/decodemethods that explicitly handle schema versions. - Upcasting and Downcasting: The key principle is that "old code cannot be taught anything." Thus, new code must be capable of both:
- Upcasting: Receiving an old shape from an old node and converting it to the new shape.
- Downcasting: Sending the old shape to an old node, preventing the old node from encountering an unknown schema.
- Peer Version Awareness: Each
tellusnode announces its application version. The sending node uses this information to determine whether to downcast a message to an older schema version for a specific peer. - Explicit Versioning: Each payload carries its schema version. Default
Schemaimplementations refuse unknown versions, turning them into dead letters with warnings rather than silently corrupting data. Vec<T>andSchema:tellusintentionally does not implementSchemafor generic containers likeVec<T>ifTis a customSchema. This is because a container would be encoded as a single payload, bypassing the element-wise schema versioning logic and potentially hiding incompatible changes within the elements.- Limitations: Messages sent before a connection is fully established, when the peer's version is unknown, will default to the oldest supported schema, potentially sending incomplete data even if both nodes are technically new.
- Rigorous Testing: The solution is validated through a "chaos verifier" in a cluster demo, which simulates rolling upgrades and downgrades between application versions, confirming that the schema evolution mechanism works as expected under various conditions.
In essence, tellus tackles schema evolution head-on by embedding versioning directly into the data transmission layer. By enforcing explicit upcasting and downcasting logic within the Schema trait and leveraging peer version information, it provides a robust mechanism to ensure data integrity and system stability during the inevitable evolution of message formats in a distributed application's lifecycle.