Video series · Episode 5 · 8–10 min

Service policies: interceptors that do one thing

Give the horizontal concerns a home. A service policy is a single-responsibility, configuration-driven, order-agnostic interceptor in the Chenile pipeline.

← All episodes

Episode goal: define “service policy” precisely and show why the three interceptor rules make policies reusable and safe to compose.

Cold open
On camera: “Last episode our service was pure business logic. Great — but the auth, logging and tenancy have to live somewhere. That somewhere is a service policy.”
Definition
Lower third: “A service policy = an implementation of a horizontal requirement that cuts across services.” Voiceover: “In Chenile, a policy is an interceptor that runs around a service operation.”
On screen
Animate a request becoming a ChenileExchange, then passing through a stack of interceptors — security, tenancy, i18n, logging — before reaching the impl, and back out again.
The three rules
Voiceover, one at a time: (1) One and only one — each interceptor implements a single policy; and only one interceptor owns a given policy, so there’s exactly one place to fix it. (2) Configuration-driven — steered by typed extension keys supplied at deploy time, not hard-coded. (3) Orchestration-unaware — it never assumes its position; it may declare before/after payload, but never hard-wires order.
Why it matters
Voiceover: “Those three rules are what make a policy testable in isolation, reusable across services, and changeable in one place. That’s the opposite of the duplicated plumbing from episode two.”
Demo
Show a simple interceptor implementing one policy (e.g. request logging or an error envelope). Attach it via service-registry configuration — no change to the service impl. Call the service; show the policy firing.
Contrast
Split screen: the old inline version (business logic tangled with a try/catch and a user lookup) vs. the Chenile version (clean impl + one interceptor). “Same behavior. One of these you can reuse.”
Cliffhanger
“Now the interesting question. If a policy isn’t welded to a service, where should it run? Next: the gateway and the last mile.”
Recap card
“A policy is a single-responsibility, config-driven, order-agnostic interceptor. Write it once; attach by configuration.”

Companion reading: Service policies: the other half of the division