Service architecture patterns

Table of Contents

1. Summary

ORE Studio is a set of services that talk over NATS, share no tables, and act for many tenants and parties. The problems that come from this are not new. Every microservice platform meets them, and the literature names the solutions: Token Exchange, Saga, Idempotent Receiver, Bulkhead. This hub is the pattern language of the platform. It lists the established patterns ORE Studio uses, and each page states the pattern's forces, its failure handling, its pitfalls, its use here and its sources.

The purpose is a shared vocabulary. A design says "use Token Exchange" and links one page. The reader then knows the mechanism, the known failure modes and how a timeout or a retry is handled, and nobody finds them again by accident.

Three rules govern the language:

  • The established name. A page is titled with the pattern's name in its source. A local name is an alias.
  • A source for every pattern. A solution with no authoritative source is a local convention, and it belongs in an architecture page, not here.
  • The pattern owns the mechanism; the user owns the use. A pattern page names each use and links it. The architecture page that uses a pattern links the pattern and states only its own choices. Document type: service_architecture_pattern states the contract.

2. Scope

The hub covers the patterns that govern how services work together across a process boundary. It does not cover code-level design patterns inside one component, user interface patterns, or the local conventions of the codegen, such as the SQL, HTTP and shell entity patterns: those have no outside source and keep their own pages. Document type: service_architecture_pattern states the boundary.

3. Reading order

Read the groups in order. Each group answers one question about two services that must work together, and a later group often uses an earlier one.

3.1. The identity group

Who is this request acting as, and how does the next service know? A request carries an identity from the edge to the database, where row-level security uses its tenant and party. These patterns decide which identity a call carries: the caller's, the service's own, or one exchanged for a purpose. Work that starts from a schedule has no caller, and the composite pattern in this group covers it.

Read Access Token first, then Client Credentials and Token Relay, which are the two ways a call carries a token it already has. Token Exchange and Grant Management come next, for an identity no call carries. The composite comes last.

Pattern Source
Access Token microservices.io; RFC 7519
Client Credentials RFC 6749, section 4.4
Token Relay RFC 8693, delegation semantics
Token Exchange RFC 8693
Grant Management OpenID Foundation, Grant Management for OAuth 2.0
Scheduled Work Acting as a Tenant (composite) the three patterns above it

3.2. The communication group

How does a message get from one service to another, and back? The bus carries requests, replies and events. These patterns decide how a reply finds its request, how bulk data travels, and how several replicas share the work.

Pattern Source
Request-Reply Hohpe and Woolf, Enterprise Integration Patterns
Correlation Identifier Hohpe and Woolf; Newman
Claim Check Hohpe and Woolf
Competing Consumers Hohpe and Woolf; Azure Architecture Center

3.3. The coordination group

How does work that spans services stay consistent? No transaction spans two services. These patterns decide how a long piece of work is sequenced, how it is undone, and how a step survives being delivered twice.

Pattern Source
Saga Garcia-Molina and Salem; microservices.io
Process Manager Hohpe and Woolf
Idempotent Receiver Hohpe and Woolf

3.4. The resilience group

What happens when a service is slow, gone or wrong? Every call can fail. These patterns bound how long a caller waits, decide when to try again, and keep one failure from spreading.

Pattern Source
Timeout Nygard, Release It!
Retry Azure Architecture Center; Nygard
Bulkhead Nygard; Azure Architecture Center

3.5. The load group

What happens when many tenants want the same thing at once? Thousands of tenants share one platform. These patterns absorb a peak, cap what one tenant can take, and share capacity fairly.

Pattern Source
Queue-Based Load Leveling Azure Architecture Center
Throttling Azure Architecture Center
Fair Share Azure Architecture Center, Priority Queue; fair-share scheduling

3.6. The data group

Who owns data, and how does another service read it? A service owns its tables and serves them through operations. These patterns state that boundary and how a reader keeps a copy without owning it.

Pattern Source
Database per Service microservices.io
Cache-Aside Azure Architecture Center

3.7. The observability group

How does a person follow what one action did across services? Each service writes its own logs and no transaction spans them. These patterns join the records of one action, show which service called which, and say where the time went. Correlation Identifier, in the communication group, is the first step; the patterns here build on it.

Pattern Source
Distributed Tracing microservices.io; W3C Trace Context; OpenTelemetry
Log Aggregation microservices.io

4. Choosing a pattern

Start from the question, not from the pattern. Find the group whose question your design faces, then read the pages in that group. Each page's * Context says when the pattern applies and * Related patterns names the alternatives. When no pattern fits, write the design without one and record the gap on the story. Do not stretch a pattern to fit.

To add a pattern, run compass add service_architecture_pattern with its group, fill in every section, cite its source, and add it to its group above. See How do I create a new doc?.

5. What this cluster does not cover

Identity and Access owns the IAM model: accounts, roles, permissions and row-level security. The identity group here owns how an identity travels between services.

Workflows owns the workflow engine. The coordination group names the patterns the engine implements; the engine's own contract stays in that cluster.

Message Queue owns the subject grammar and the message contract. The communication group names the patterns the bus carries.

NATS service patterns owns how each pattern is written on this bus: the ores.nats call, its arguments and the failure without it. The two hubs divide the work, and each states the boundary. Read a pattern here to choose the mechanism; read its NATS page to write it. A page here reaches the NATS page it specialises from its * NATS patterns section, and a NATS page names the pattern here it specialises.

6. See also

Emacs 29.3 (Org mode 9.6.15)