AlgoViz

DRY

easy 40 min

Don'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 shareOne home at run time?Cost of a changeGood for
Copy by handNon editsTwo lines that rarely change
Shared libraryNo, versions differ1 edit and n upgradesTechnical code: logging, retries, formats
Service that answersYes1 release, all see itRules that must be equal at once
Schema and generatorThe shape only1 edit, n buildsMessages and API clients
Table of examplesNo, but differences are caught1 edit, n test runsSmall rules in many languages

A change of a shared rule

Ship the code first, switch the behaviour by date later. Then the versions may differ and the answers do not.

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