Repository navigation
Open
Labels
BacklogNot started: the work waits in the backlogfeatureA capability that a user seesstatus:openNo fix yet
Description
The owner's goal (2026-11-14)
"make sure that we have an excellent and well designed system that is very resilient and that we can even spin 2 or 3 cmapi pods and it will work well (we have the postgresql key value pair)"
Each of the three instances (nonprod, staging, prod) must run 2 or 3 replicas of the API and of the worker, survive the loss of any pod, and behave exactly as with one.
Read at main (2026-11-14)
Already replica-safe:
- Jobs:
SELECT ... FOR UPDATE SKIP LOCKEDwith a lease (cmapi/src/cmapi/worker.py,core/db/repo.py:249). - Request IDs under
pg_advisory_xact_lock(core/db/repo.py:140); migrations underpg_advisory_lock(core/db/migrations/env.py:30). - Idempotency keys and the per-namespace request lock are database constraints; the auto-approval switch is a database row.
- The chart has
replicasper component and a PodDisruptionBudget template (deploy/helm/cmapi/templates/api.yaml:95).
Not ready or not proven:
- Every component defaults to 1 replica (
deploy/helm/cmapi/values.yaml:176-189,deploy/manifests/components/cmapi/20-api.yaml,30-worker.yaml). core/ratelimit.pykeeps token buckets in memory per replica ("the limits are set per replica count"), so N replicas give a caller about N times the limit.- Per-pod caches: JWKS, the watch cache of each cluster, the directory cache. Correct for reads, but N times the watch load on each cluster and on Keycloak.
- No test runs more than one API or worker process at once.
What to build
- An audit of every piece of in-process state (caches, timers, the rate limiter, anything a single process assumes), each marked: safe per pod, moved to PostgreSQL, or leader-only. Record it in docs/02 ("Scaling").
- Shared state in PostgreSQL, not Redis or Valkey (the owner's rule; kvpg
inkcasthq/kvpgcontract v1 is the reference, or a vetted Python library, asOB1-PROMPT.mdsays). First user: an instance-wide rate limiter, so the configured limit holds whatever the replica count. - Leader-only work where exactly one pod must act (for example the cluster watches or a periodic collector): a PostgreSQL advisory-lock leader with a lease and fast failover; the other pods stand by.
- Kubernetes: default
replicas: 2(or 3 for prod) for the API and the worker; PodDisruptionBudgetminAvailable: 1; topology spread or anti-affinity across nodes; readiness that fails while draining; graceful SIGTERM (finish or release the job lease); database pool size × replicas withinmax_connections, with the numbers written down. - Proof, in two steps:
- Now, with no containers (PERF-01: container load on the CRC Mac (kind, act) makes keycloak-0 fail its probes; killed at 08:58Z and 15:38Z on 2026-11-13 #157): start 3 API processes and 2 worker processes on cmapi-test-pg; run the full flow concurrently; kill a worker in the middle of a job and show the job finishes on the other; show the rate limit holds across the 3 APIs; show no duplicate request IDs, jobs or PRs. This is a test in the suite, not a one-off.
- Later, on kind and then CRC when PERF-01: container load on the CRC Mac (kind, act) makes keycloak-0 fail its probes; killed at 08:58Z and 15:38Z on 2026-11-13 #157 allows:
replicas: 3, a pod deleted during a request, a node drained, and the load test of Wave 8.
Done when
The audit, the changes, the native multi-process test and the docs are merged; the twelve-factor row VIII (concurrency) is scored on that test; the cluster proof is filed for Wave 8.
Metadata
Metadata
Assignees
Labels
BacklogNot started: the work waits in the backlogfeatureA capability that a user seesstatus:openNo fix yet
Activity
Records: the owner's decisions of 2026-11-14 (#215, three instances, #…
ephico2real2 commentedon Nov 14, 2026
From Fable's review of #238 (the front door), to handle here:
portal.replicasis 1, and every call to the API, the CLI's too, now passes that one pod. With 2 or 3 API pods, the front door needs 2 replicas and a spread over nodes too.