Skip to content

Commit 25b6642

Browse files
authored
Support for forward and backward compatibility in DCL schemes (#540)
* Add schema compatibility document * Revise and clarify the schema compatibility document * Update schema compatibilty document structure * Update schema compatibility strategies * Change the structure of the schema compatibility document
1 parent 183290b commit 25b6642

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

docs/design/schema-compatibility.md

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Support for forward and backward compatibility in DCL schemes
2+
3+
Schema changes can cover a wide range of modifications with varying impacts on application compatibility and data integrity. Below are use cases with strategies to manage schema changes and ensure compatibility.
4+
5+
## I. Multiple versions can live in parallel
6+
7+
### 1. Strategy for Compatible Changes
8+
9+
For changes that are backward-compatible, such as adding optional fields or extending enumerations.
10+
11+
#### Option A: Add an optional version field to all DCL schema
12+
13+
**Description:**
14+
Implement an optional version field in all DCL schemas to track the schema version. This approach is simple and quick to execute, suitable primarily for compatible updates.
15+
16+
**Strategy steps:**
17+
18+
- One time actions:
19+
- Add an optional version field to all DCL schema
20+
- For each update:
21+
- Update the schema by introducing compatible changes (such as adding a new optional field).
22+
- Update transactions and queries if needed.
23+
- DCL doesn't fulfill the Schema version automatically
24+
- It will be up to the transaction submitter (Vendor) to specify a correct Schema version
25+
- If Schema Version is not set - then the initial version (version 0 or 1) is assumed
26+
- It will be up to the client application to process the Schema version
27+
28+
### 2. Strategy for Non-Compatible Changes
29+
30+
For significant changes that directly impact compatibility, such as adding mandatory fields or removing fields, splitting or merging schemas, changing enumerations.
31+
32+
#### Option B: Separate Schemas for Each Version
33+
34+
**Description:**
35+
Each version has its distinct schema, state and its own queries/requests. This strategy eliminates the need for data migration and allows different schema versions to coexist seamlessly.
36+
37+
**Strategy steps:**
38+
39+
- For each update:
40+
- Create a new version of a Schema and state (a new .proto file)
41+
- Implement transactions and queries for the new schema version.
42+
43+
#### Option C: Generic Schema Storage (Not Recommended for Production)
44+
45+
**Description:**
46+
Implement a flexible, generic schema structure that can support a wide range of data formats.
47+
48+
While offering a robust solution for handling radical changes, this method requires careful planning and development, which can potentially take a significant amount of time.
49+
50+
**Strategy steps:**
51+
52+
- One time actions:
53+
- Create a more flexible, generic schema structure to hold a wide range of data formats (Can be used [Any](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/any.proto) as described in [ADR-19](https://docs.cosmos.network/v0.47/build/architecture/adr-019-protobuf-state-encoding#usage-of-any-to-encode-interfaces))
54+
- Migrate old states to the newer, generic schema.
55+
- Remove the states associated with the older schema versions.
56+
- Optioanlly can be implemented queries for requesting schemas with any return type
57+
- For each update:
58+
- Create a new Schema version (a new .proto file)
59+
- Implement transactions and queries that can handle data according to its version, including mechanisms for converting generic values into the corresponding schema version.
60+
61+
## II. New version replaces the legacy one (V2 replaces V1)
62+
63+
### 1. Strategy for Compatible or Convertible changes
64+
65+
For changes that are backward-compatible, such as adding optional or mandatory fields or extending enumerations
66+
67+
#### Option D: Not keeping backward compatibility in API
68+
69+
**Description:**
70+
This strategy focuses on updating the schema without ensuring backward compatibility at the API level. Since the schemas are compatible, there will likely be no need for migration.
71+
72+
**Strategy steps:**
73+
74+
- For each update:
75+
- Update the schema by introducing compatible changes (such as adding a new optional field).
76+
- Migrate old states to the newer if needed.
77+
- Update transactions and queries if needed.
78+
79+
#### Option E: Keeping backward compatibility in API
80+
81+
**Description:**
82+
The main idea of this strategy is the dynamically converting newer schemas into older ones. However, this method is only possible if there is compatibility between the newer and legacy schemas, allowing them to be converted to each other. Due to the on-the-fly data conversion, this approach does not support the Light Client in legacy APIs because the converted data is not stored in the state, preventing the generation of proofs.
83+
84+
**Strategy steps:**
85+
86+
- For each update:
87+
- Create a new version of a Schema and state (a new .proto file)
88+
- Migrate older states to newer schema version.
89+
- Remove the states associated with the older schema versions.
90+
- Implement transactions and queries for the new schema version.
91+
- Update older transactions and queries to converting data between the latest and older schema version, ensuring backward compatibility.
92+
- There will be separated API for each version of the schema, for example::
93+
- models/vid/pid
94+
- modelsV2/vid/pid
95+
- modelsV3/vid/pid
96+
97+
### 2. Strategy for Non-Compatible changes
98+
99+
For significant changes that directly impact compatibility, such as adding mandatory fields or removing fields, splitting or merging schemas, changing enumerations.
100+
101+
#### Optiona F: Not keeping backward compatibility in API
102+
103+
**Description:**
104+
This strategy focuses on updating the schema without ensuring backward compatibility at the API level. Since the schemas are not compatible, migration is carried out manually through a special transaction.
105+
106+
**Strategy steps:**
107+
108+
- For each update:
109+
- Update the schema by introducing changes.
110+
- Update transactions and queries if needed.
111+
- Add a new transaction to fulfill new required fields (essentially this is a manual migration via transactions)
112+
113+
#### Option G: Keeping backward compatibility in API
114+
115+
**Description:**
116+
It's not possible to replace an old version here. [Multiple versions can live in parallel: Strategy for Non-Compatible Changes](#2-strategy-for-non-compatible-changes) options should be used instead.
117+
118+
## Conclusion
119+
120+
To lay the foundation for future compatibility improvements, it's a good idea to start by adding a version field to each schema. For subsequent changes, we will then select the most appropriate strategy based on the nature of these changes.

0 commit comments

Comments
 (0)