DRY
easy 40 minDon't repeat yourself: every piece of knowledge has one home, and everything else asks that home.
Watch lesson4:18
Across services
Sharing inside one program is easy. Between teams it is a contract.
The point: between services, share contracts and examples first, libraries second, and domain classes almost never.
Numbers
Why a shared library is not one copy
Suppose 12 services use price-rules 1.4, and version 1.5 changes the rounding. Each service upgrades on its own day. Between the first and the last upgrade, two rules are live. So a library removes copies in the repository, and not at run time.
| Way to share | One home at run time? | Cost of a change | Good for |
|---|---|---|---|
| Copy by hand | No | n edits | Two lines that rarely change |
| Shared library | No, versions differ | 1 edit and n upgrades | Technical code: logging, retries, formats |
| Service that answers | Yes | 1 release, all see it | Rules that must be equal at once |
| Schema and generator | The shape only | 1 edit, n builds | Messages and API clients |
| Table of examples | No, but differences are caught | 1 edit, n test runs | Small rules in many languages |
A change of a shared rule
Trap
The shared model package
Teams like to share a package with User, Order and Product. A cart sees an order as open lines. A warehouse sees boxes. Invoicing sees a fixed document. One class for all gets 40 optional fields, and no field can be removed. The three orders share a name and an id. They are three models.
Share between teams
- Message schemas with versions
- Example files that all suites run
- Small technical libraries
- Ids and formats of ids
Think twice
- Domain classes with behaviour
- Database tables
- A util package that everybody edits
- Anything without an owner