Linora

0021. Service topology: realtime, API, doc workers, compactor, Postgres

Status: Accepted (2026-11-27). Supersedes the process layout of 0009.

Context

The realtime tier must never materialize full documents (ADR 0019), yet queries, MCP outlines, PNG render and compaction need them. Hand editing, 100k sockets and heavy reads must not compete for the same memory or event loop.

Decision

| Tier | Package | Runtime | State | Scales by | |—|—|—|—|—| | Edge LB | (infra) | managed LB / HAProxy | none | - | | Realtime gateway + room owners | apps/realtime | Node 26 + uWS.js, threads (ADR 0020) | sockets, rooms, structural indexes, rings | file-id hash across instances | | API service | apps/api | Node 26 node:http | none (DB + small caches) | stateless replicas | | Doc workers | apps/docworker | Node 26 processes | LRU of materialized pages, hard memory cap | page-id hash across workers | | Compactor | apps/docworker --mode=compactor | separate processes, one job at a time | one page while compacting | job queue | | Postgres | - | managed or self-hosted | relational + journal + snapshot metadata | vertical, read replica | | Blob store | S3-compatible or local disk | - | immutable snapshot + structure files | - | | MCP | apps/mcp | Node 26, stdio or Streamable HTTP | per agent session only | stateless replicas |

How they talk

Alternatives

Consequences

Single-box dev runs all tiers as separate npm run dev:* processes against Docker Postgres and a local blob directory. Production adds tiers independently.