Part II: Concurrency, Services & APIs
Part II covers building concurrent, long-running services, API servers, and multi-binary distributed systems using the locus model.
Core Concepts
Section titled “Core Concepts”- Lifecycle (
birth→run→drain→dissolve): Every running locus follows a deterministic four-phase lifecycle managed by the runtime, with teardown cascading depth-first through child subtrees. - Typed Message Bus (
topic&bus): Loci communicate asynchronously by publishing and subscribing to typedtopicdeclarations. Keyed topics (keyed_by) route traffic directly to the owning child or worker replica. - Thread Placement (
placement { }): Loci are single-threaded inside their own methods. Concurrency is configured inmain locusby assigning children tocooperative(pool = ...)(with optionalwhere async_ioepoll/kqueue coroutines) orpinned(core = N, replicas = K). - Supervision (
closure&on_failure): Loci declare state invariants (closure) and parents define recovery policies (restart,restart_in_place,bubble). - Seams & Repositories (
seam&@repo(T)): Linear typed pipelines (seam) route union message sets (type Inbound = A | B;) with compile-time exhaustiveness checks, while@repo(T)standardizes keyed CRUD persistence and state effects. - Typed API Surfaces (
api&@rpc): Declare anapicontract once and serve it over HTTP RPC, REST (http::Rest), Unix sockets (unix::Rpc), gRPC (grpc::Rpc), MCP (mcp::Rpc), or WebSockets (ws::Hub), or consume external OpenAPI/MCP specs withhale api import. - Multi-Binary Fleets (
bindings&fleet locus): Rebind topics across processes (unix,shm_ring, broker adapters) and verify multi-binary topologies in source withfleet locusandhale deploy render.
Chapters in Part II
Section titled “Chapters in Part II”| Topic | Chapters |
|---|---|
| Lifecycle, Bus & Concurrency | Locus Lifecycle · The Typed Message Bus · Concurrency & Thread Placement · Ownership, Children & Flow Reclamation · Supervision & Structural Failure |
| Boundaries & Data Access | Interfaces, Contracts & Perspectives · Seams & Typed Pipelines · Repositories (@repo) · Service Composition Patterns |
| APIs & Distributed Systems | Tutorial: Build a Typed API · API Surfaces, RPC, REST, MCP & gRPC · API Wire Schemas & Compatibility · Multi-Binary Systems, Fleets & Deployment · The Application Model |