System-design process for large backend features that span several modules, workers and data flows - AI/LLM serving, recommendation feeds, notification pipelines, upload/processing pipelines, search, grading systems, real-time features. Use whenever the user wants a big/major/complex feature, "design the architecture of X", scalability, a pipeline, multi-step flows, ML in the backend, or asks how a top company would structure something - produces a design doc, then splits it into buildable ph...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Fastapi Major Feature?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/amralhorimy-fastapi-major-feature)
---
name: fastapi-major-feature
description: System-design process for large backend features that span several modules, workers and data flows - AI/LLM serving, recommendation feeds, notification pipelines, upload/processing pipelines, search, grading systems, real-time features. Use whenever the user wants a big/major/complex feature, "design the architecture of X", scalability, a pipeline, multi-step flows, ML in the backend, or asks how a top company would structure something - produces a design doc, then splits it into buildable phases.
---
# Major Feature / System Design
Use when a feature cannot be one module. Output = **design doc** (template below) + **phase plan**
(`fastapi-phase-planning`). Do not write code until the design has been agreed.
## Process
1. **Problem and users** - what must be true after launch; what is explicitly not a goal.
2. **Non-functional requirements** - latency target, throughput, data volume, freshness, availability,
cost/resource ceiling (e.g. "CPU only", "one 8 GB box"), privacy. Numbers, even rough ones.
3. **Data model + flows** - entities, who owns them, the main flows as numbered sequences:
`client -> router -> service -> store -> event -> worker -> store -> push to client`.
4. **Sync vs async cut** - decide from the user-facing latency budget and operation semantics, not a universal time threshold. Keep short,
bounded work in the request when the caller needs its result immediately and request-scoped failure is acceptable. Use an in-process
background task only for brief, best-effort work whose loss on process restart is acceptable. Use a durable queue/worker when accepted
work must survive restart/deploy, retry after transient failure, be rate/concurrency limited, fan out, or run independently of request
lifetime. State whether the caller waits, polls, or streams progress; define timeout, idempotency and overload behavior for either choice.
If event loss is unacceptable, persist an outbox row in the same transaction as the source write and relay it idempotently.
5. **Components** - which modules, which workers (separate containers), which stores, which channels.
One responsibility each. Draw it (Mermaid) in the doc.
6. **Failure modes** - for each component: what if it is down, slow, duplicated, out of order?
Define timeouts, retries (with backoff + cap), idempotency, dead-letter, and a degraded/failure mode appropriate to that dependency.
7. **Capacity and cost** - back-of-envelope numbers; the first bottleneck; the cheap fix.
8. **Rollout safety** - feature flag, shadow mode (compute but do not serve), gated rollout by
percentage/cohort, and a kill switch. Define rollback/fallback per component: claim automatic fallback only where the previous path
remains correct and operational; otherwise specify a safe disabled/degraded mode, data reconciliation, and operator action.
9. **Measurement** - the metric that says it works (and a guardrail metric that says it hurts).
Offline evaluation before any online exposure for ML parts.
10. **Phases** - hand to `fastapi-phase-planning`; each phase independently shippable and reversible.
## Design principles (what "professional" means here)
- **Phase the risk.** Our real feed went: 1 interactions + signal capture, 2 heuristic feed + cache, 3 embeddings, 4 learned ranker (data foundation first, then export/train/gate/shadow/rollout; two-tower deferred). Each phase shipped alone.
- **Write the ADR when you reject an alternative** (`$inc` counters, Outbox, Kafka, Celery) and name the trigger to revisit.
- **Baseline first.** A simple heuristic that works becomes the fallback and the yardstick for anything smarter.
- **Separate the hot path.** Serving reads precomputed/cached results; heavy computation runs offline/in workers.
- **Log for the future.** Record impressions/inputs/decisions with a `snapshot_id` or version so results can be
replayed, audited and used for training later.
- **Everything versioned.** Models, rankers, prompts, rubrics, schemas - stored with the version that produced
each result.
- **Isolate scarce resources.** One worker type per heavy model, concurrency capped by semaphore, queue length
bounded, backpressure visible (HTTP 429/503 with `Retry-After`).
- **Define failure behavior per dependency.** For each store, queue, provider, model, and cache, state timeout, retry/circuit-breaker policy,
whether the request fails, queues for later, serves stale data, or drops work, and how recovery/reconciliation is detected. A universal
fallback is unsafe when it changes correctness or loses accepted work.
- **Idempotent consumers** everywhere events are used.
## Patterns library (proven in a real social backend)
| Need | Pattern |
|---|---|
| Slow result | If it exceeds the caller's latency budget or needs durable retry/isolation, use a Redis-Streams job queue + status + pub/sub/SSE; persist final result once (`fastapi-async-workers`). A brief best-effort task may stay in-process only if restart-loss is acceptable and explicit. |
| Local LLM | separate `llm_worker` image/entrypoint; adapter behind a port (fake for tests); single-question route (wait) + chat route (stream); concurrency 1-2 |
| Token streaming | worker publishes chunks on a per-job channel; API relays via SSE; subscribe -> read state -> relay |
| React to user actions | one event per real change on `events:interactions`; independent consumer groups (counters, archive, notifications, feed-seen); counters **recounted** from source |
| Cross-module need | consumer-owned port + bridge in `entrypoints/bridges.py`; each module keeps its own read model |
| Personalised feed | candidates (followees, trending, fresh) -> score `engagement x decay x proximity` -> store a **snapshot of ids** per user in Redis -> page through it with an **HMAC-signed cursor**; next page = 2 queries, no recompute; invalidate on follow/unfollow via generation counter |
| Embeddings similarity | separate embedding worker (small multilingual CPU model), post vector + user interest vector, similarity candidates, vectors versioned by model |
| Learned ranker | serving log with `snapshot_id` -> dataset builder -> baseline + offline eval -> **shadow** -> **gated** rollout (`RANKER_MODE`), heuristic stays as fallback; accumulate data before training |
| Notifications | event -> create record -> dispatcher **port** (inline only when bounded and loss/retry semantics are acceptable; durable queue/outbox when delivery must survive restart) -> push sender adapter (log provider for dev, FCM prod) -> mark delivered; log each hop with one correlation id |
| Heavy upload processing | presigned upload -> storage webhook (authenticated, idempotent) -> job -> status machine |
| Multi-model pipeline (e.g. HTR + grading) | adapters behind one interface, fakes first, evaluation lab comparing adapters, rubric/version pinned to each result |
| Admin/ops | RBAC permissions as data, fresh sign-in for staff actions, tamper-evident audit module, detection rules, metrics |
## Design doc template
```
# Design: <feature>
## 1 Problem / goals / non-goals
## 2 NFRs (numbers)
## 3 Data model (collections, indexes, ownership)
## 4 Flows (numbered) + Mermaid diagram
## 5 Components and responsibilities (modules, workers, channels, keys)
## 6 Contracts (API, events, statuses) - link to schemas
## 7 Failure modes table: component | failure | behaviour | detection
## 8 Capacity & cost
## 9 Security & privacy
## 10 Rollout (flags, shadow, gates, rollback)
## 11 Metrics & alerts
## 12 Phases (from planning skill) and what is deferred
## 13 Open questions / decisions (ADR links)
```
## Review gate before building
Ask: What is the first thing that breaks at 10x load? What happens if the worker dies mid-job? How do we
turn it off in 10 seconds? How would we know it is silently wrong? If any answer is "we don't know",
the design is not done.