CSE Roadmap

Core tier · about 4 hours · 8 parts

Part 6 of 8 · 2 min read

Data and code

Pass a reference, and be careful with client libraries.

Access by reference. When a service fetches a customer, what it holds is a memory of what the customer looked like then. The longer it holds that memory, the more likely it is false. BM's advice: when a memory is passed along, include a reference (a link) to the original, so the current state can be fetched.

BM's example is an email service asked to send "order shipped". The request could carry the name, address and order details. But if the request waits in a queue, the details may change. It may be better to send only links to the customer and the order, and let the email service look them up at send time. For events the opposite helps: an event says what the customer looked like when it happened, plus a link to the current record. Trade-offs: always fetching puts load on the owner, and caching with a freshness time reduces it. BM adds that sending the full record may couple a service to things it does not need. There is no hard rule, but be wary of passing data whose freshness is unknown.

Client libraries. Some teams ship a library with each service so that callers do not need to write the call code. BM warns that when the same team writes both sides, logic that belongs on the server leaks into the client, cohesion drops, and a fix needs many clients to change. He praises the Amazon Web Services model: SDKs are written by people other than the API team, and the client decides when to upgrade. He also notes that Netflix libraries handle discovery, failure and logging for reliability at scale, and that over time they created coupling. His advice has three parts: keep transport code apart from code about the target service, decide whether use of the library is mandatory, and let clients choose when to upgrade.

Check yourself: 1. Why can an event carry a copy of the data while a queued request should carry a reference? 2. What goes wrong when one team writes a service and its client library? 3. Who should decide when a client upgrades its library?