- Compatibility between several programming languages.
- Message passing must be fast.
- Rolling upgrades make it necessary that services be backward and forward compatible.
- Messages must be compact to reduce data transfer costs in public cloud.
See git repository for a client server demo of Thrift.
https://github.com/sholavanalli/apache_thrift_demo
- Developed and open sourced by FB. Still widely used.
- Encoded data contains field tags. They are compact aliases for a field.
- Field names can be changed but tags cannot be changed since field names are never in the encoded data.
- Forward compatibility (old code can work with new code): New fields can be added provided they are given new tag numbers.
- Backward compatibility (new code can work with old code): As far as new fields are not marked as required, new code can
read old data. - Optional fields can be removed and that tag number should not be used again.
It is not a good idea to use Thrift when we’re working with legacy RPC systems. Lot of code must be re-written or duplicate code must exist to bridge the legacy code and the Thrift generated code.
- Not compact. Field names are encoded.
- As fields are encoded they cannot be removed or renamed. Hard to maintain forward and backward compatibility.
- Have to write lot of code for marshalling, unmarshalling, validation and exception handling.
- Ambiguity around encoding of numbers. Doesn’t distinguish integer and floating point numbers. Doesn’t specify a precision. Large integers cannot be represented in double precision floating point numbers.
- Passing a sequence of bytes without a character encoding cannot be done without hacks.
See git repository for a client and server demo of Jackson with JAX-RS.
https://github.com/sholavanalli/jax_rs_jackson_demo
- No need to write extra code for marshalling, unmarshalling, validation and exception handling.
- Backward and forward compatibility is possible as Jackson can ignore unknown properties and set defaults to removed properties.
- Works nicely with legacy RPC systems, especially when used with JAX-RS.