In Thrift, the primary purpose of parameter numbering is to ensure cross-version compatibility. Each field or parameter is assigned a unique number, allowing both parties to correctly identify and process these fields even if certain fields are added, removed, or modified in subsequent protocol versions.
For example, consider the following Thrift service definition:
thriftstruct Employee { 1: string name; 2: int32 age; 3: string position; }
In this struct, the name field is assigned number 1, the age field is assigned number 2, and the position field is assigned number 3. If, in a future version, we decide to remove the position field and add a new email field, the new definition might look like this:
thriftstruct Employee { 1: string name; 2: int32 age; 4: string email; }
Here, the email field is assigned a new number 4. Even though the position field is removed, numbers 1 and 2 remain unchanged, meaning that older versions of clients and servers can still correctly parse the name and age fields, ensuring backward compatibility.
In this way, Thrift allows service interfaces to be iteratively updated without disrupting communication between existing clients and servers. This is particularly important for large, distributed systems where components may not be able to update simultaneously.