Caching and Error Translation in the Resources Layer
Caching and error translation both hide something from callers: where data came from and how a vendor fails. See how the Resources layer handles each.
Nobody puts "we might switch vendors" on a roadmap, and then a hospital customer switches vendors. For a platform that reads from electronic health record systems, that day is a certainty rather than a risk. The book's MedConnect example answers one narrow question: where should the boundary sit so the day stays small?
MedConnect has to talk to EHR platforms whose interfaces differ. Some speak FHIR, some HL7v2, some a proprietary REST dialect. The book's answer has two parts. A single vendor-neutral interface is declared in Schema, the lowest layer, and each vendor gets its own implementation in Resources. Tools program against the interface and never name a vendor.
The quiet decision is the placement. An interface declared beside its implementation tends to pick up that implementation's habits: field names, status codes, error shapes. Declared in the most stable layer, the contract is written in the platform's own vocabulary, and each vendor has to be bent to fit it rather than the reverse. That reading is mine, not the book's, but it explains why the interface sits where it does.
The book walks through a hospital moving from one vendor to another. The interface in Schema does not change. A new class in Resources implements it over HL7v2 messages in place of FHIR JSON. Tools, API and every layer above need no modification, because none of them ever depended on the old vendor.
Here is the shape of it in a smaller sketch with my own names:
// Schema (L1): the platform's own words
export interface PatientDirectory {
findById(id: PatientId): Promise<Patient | null>;
}
// Resources (L3): one class per vendor
export class MessageBusDirectory implements PatientDirectory {
constructor(private gateway: Gateway) {}
async findById(id: PatientId) {
const reply = await this.gateway.request({ kind: "demographics", id });
return reply.found ? toPatient(reply.segments) : null;
}
}
Two details carry the weight. A missing patient comes back as null, the platform's own idea of absence, rather than as whatever the vendor's gateway happens to throw. And toPatient is a plain function that turns the vendor's payload into the domain type. In the book's own code the mapping functions are imported from Utils, so the translation is pure and can be exercised with a pile of sample messages and no network.
Everything vendor-shaped therefore stops at the adapter's edge. The vendor is confined to one layer, which is what lets it be replaced there without ripple effects.
Every method on the interface is a promise that each future vendor must keep. If one vendor offers something the others lack, resist widening the shared contract for it. Add a separate, optional interface that Tools ask for explicitly. This is general practice rather than a rule from the book, but it is what stops a one-class migration from quietly becoming a three-class one.
A well-placed contract also gives you a cheap safety net, and this one is general practice rather than something from the book. Write one suite of behavioural tests against the interface and run it against every adapter. The new vendor's implementation either passes the suite or shows exactly which promise it breaks, before any clinician sees it. For how those tests are structured at this layer, see testing the Resources layer.
The interesting thing about vendor isolation is how little code it involves. What matters is that the contract lives below the volatile part, that the vendor's vocabulary is translated at the border, and that nothing above ever reaches around the contract. The book supplies the retry, circuit-breaker and encryption machinery that surrounds a real adapter. For the underlying patterns, read repositories, adapters, facades and anti-corruption layers, and for the wider case study, MedConnect layer by layer.