Don't speak public protocols, ship mobile libraries instead

Epistemic status: Hot take.

When a programmer creates some new kind of network service, they often make the mistake of creating a documented and backwards-compatible protocol as public interface of that service. This is a completely wrong approach; it makes upgrading the service much harder and requires significant inefficiencies in the protocol for backwards-compatibility and ease of implementation.

Far better for the interface of the service to be a simple set of language-level functions, provided by a library shipped and updated through mobile code, which speaks a completely internal protocol to the network service.

Instead of an application connecting to your service through some library they installed, your service should send library code to the application as part of the initial handshake, which the application can then execute to speak your internal protocol.

Then you can model the library as simply an extension of the service, under the direct control of the service's main loop. Instead of tiresome serialization and deserialization, simply centrally manage the lifetime of remote memory and objects in the service, and just RDMA bytes directly into remote memory.

Directly modeling remote (client-side) objects, and writing code to manipulate them as an extension of your program, makes it much easier to keep the whole system in your head. After all, one program is simpler than two!

Likewise, instead of carefully extending your protocol and upgrading your clients to use new features, update your protocol by shipping new code to the library and command the library to jump into it. Auto-updating in this way is much easier, plus it's more secure than complicated backwards-compatible protocols.

When you want to introduce a new language-level interface, just write an adapter that implements your old language-level interface on top of the new one. Then you can ship that code over your protocol to everyone using the old interface, and forget about it.

Created: 2018-09-23 Sun 03:19

Validate