Service Scaling¶
Status: TBD / Planned (Not Yet Built)
Only the local Docker Compose + Floci development experience exists today in stravin-dev/core (v1.12.x). Service interfaces, graceful shutdown hooks, and bounded-cardinality OpenTelemetry/Prometheus metrics are defined and implemented, while production Kubernetes autoscaling manifests, HPA/KEDA policies, and scaling controllers are TBD and will be built with the final production platform.
This document defines how Stravin Core's five Go daemons (stravin-edge, stravin-node, stravin-pack, stravin-relay [stravin-hook in v1.12.x], and stravin-ctrl) and the vNext platform foundation services (NATS JetStream, Temporal, stravin-webhooks, stravin-auth, and stravin-notify) scale up/out under increasing load, scale down/in when load subsides, and how operators and autoscalers use OpenTelemetry metrics to decide when to act.
Storage-plane ceilings (DynamoDB WCUs/shards and S3 prefix partitioning) are covered separately in Performance & Throughput Scaling; this guide focuses strictly on scaling Stravin's services.
Core Service Scaling Matrix¶
| Service | Scaling Type | Upper Bound / Constraint | Scale-Out / Scale-Up Behavior | Scale-In / Scale-Down Behavior |
|---|---|---|---|---|
stravin-edge |
Horizontal (primary) | Unbounded per region (behind L4/L7 LB) | Add stateless replicas immediately; zero warmup required | Mark unready, drain in-flight SSH/HTTP Git streams, terminate |
stravin-node |
Horizontal + Vertical | Unbounded horizontally; vertical bounded by instance NVMe/RAM | Out: Add nodes to rendezvous ring (remaps ~1/N repos). Up: Larger NVMe/RAM for huge monorepo working sets |
Conservative: Step down 1 node at a time after long cooldown to protect warm NVMe cache hit ratio; drain active streams |
stravin-pack |
Horizontal + Vertical | Horizontal capped by active manifest shards (M); vertical for Tier 1 repack RAM/CPU |
Out: Add workers up to M to claim idle shard leases. Up: Bigger CPU/RAM/NVMe for deep delta repacks |
Release shard lease cleanly after completing active two-phase manifest swap; scale down when lag clears or lease contention rises |
stravin-relay (stravin-hook in v1.12.x) |
Horizontal (primary) | Capped by DynamoDB Streams shard count | Add stream relay consumers up to active shard count to publish Standard Async Event Envelopes onto STRAVIN_CORE JetStream (zero Wasm, zero external HTTP) |
Stop polling new stream batches, flush in-flight JetStream publishes (Nats-Msg-Id), commit sequence checkpoint, terminate |
stravin-ctrl |
Fixed HA + Vertical | 1 active leader + 1–2 warm standbys (never active-active) | Vertical only (CPU/RAM/network) if post-failover parallel HeadObject scrubs saturate the leader |
Scale down vertically only after verifying failover scrub drill fits within target RTO |
Telemetry-Driven Scaling Loop¶
All scaling decisions read bounded Prometheus metrics exported via the OpenTelemetry Collector (see Telemetry & Observability). Before scaling any service out, verify that latency is not caused by an upstream/downstream bottleneck (such as DynamoDB throttling or S3 origin fallback) where adding compute would amplify retries.
flowchart TD
Metrics["Prometheus Metrics\n(OTel Collector -> LGTM)"] --> Guard{"Downstream healthy?\n(Low DDB throttle &\nlow OTel drops)"}
Guard -- "No (DDB throttled / telemetry blind)" --> Hold["Hold compute scale-out;\ninvestigate storage or OTel pipeline"]
Guard -- "Yes" --> Eval{"Threshold breached\nfor sustain window?"}
Eval -- "Above scale-out / scale-up" --> Decide{"Bottleneck shape?"}
Decide -- "Concurrency / RPS / Lag" --> Out["Scale Out\n(Add replicas)"]
Decide -- "Working set / OOM / Single-shard RAM" --> Up["Scale Up\n(Larger instance class)"]
Eval -- "Below scale-in for cooldown\n(15–30 min for stateful caches)" --> Drain["Graceful Drain\n(Flush streams / leases / checkpoints)"]
Drain --> In["Scale In\n(Remove replica)"]
Eval -- "Within band" --> Steady["Steady State"]
Per-Service Scaling Playbooks¶
1. stravin-edge (Horizontal)¶
stravin-edge terminates SSH and Smart HTTP connections, enforces auth and per-tenant rate limits, and proxies writes to home_region. It holds no persistent local state and only a tiny in-memory home_region routing cache.
- Scaling type: Horizontal. Adding instances linearly scales TLS/SSH handshakes, concurrent Git streams, and gRPC write-proxy throughput. Vertical scaling is rarely needed unless single-process network bandwidth or file-descriptor limits are reached on small instance types.
- When to increase (scale out):
stravin_edge_request_duration_seconds(p95/p99) rises whilestravin_node_request_duration_secondsremains flat (indicating ingress queuing or proxy saturation).- Sustained CPU utilization > 65–70% (SSH/TLS crypto overhead) or active concurrent connections approaching per-instance socket/goroutine budgets.
- Rising
stravin_edge_requests_totalRPS combined with non-auth5xxor timeout error classes.
- When to decrease (scale in):
- CPU utilization < 30% and
stravin_edge_request_duration_secondsp99 within SLO for a 5–10 minute stabilization window.
- CPU utilization < 30% and
- How to scale in safely: Remove the instance from load-balancer rotation via readiness probe first, then allow long-running
git clone/git pushstreams to drain beforeSIGTERMcompletes.
2. stravin-node (Horizontal + Vertical)¶
stravin-node is stateless with respect to durability (S3 and DynamoDB are authoritative), but cache-warm via local ephemeral NVMe disks and tenant-pinned sandboxes/Wasm module caches. Because stravin-edge routes requests with rendezvous hashing (HRW), changing the node count remaps only ~1/N of repositories.
- Scaling type: Hybrid (Horizontal for throughput, Vertical for working-set size).
- Horizontal scales aggregate push/fetch RPS, concurrent sandboxed
git-upload-packexecutions, and synchronouswazeroWasm hook capacity. For hot repositories routed by(tenant_id, repo_id, ref_shard), horizontal scale-out directly increases single-repo write parallelism. - Vertical (larger NVMe disk, RAM, and vCPU per node) is required when individual large monorepos or high-activity tenants exceed a single node's NVMe cache quota or
cgroup v2memory ceiling duringgit-upload-packgraph walks.
- Horizontal scales aggregate push/fetch RPS, concurrent sandboxed
- When to increase horizontally (scale out):
stravin_node_request_duration_secondsp95/p99 climbs alongside risingstravin_node_requests_totaland host CPU > 70%.stravin_hook_wasm_duration_secondsp99 exceeds the S3 upload overlap window (~15–30 ms) orstravin_hook_wasm_verdicts_total{verdict="timeout"}spikes due to Wasm bulkhead semaphore saturation (capped at 25% of host vCPUs).- Concurrent
git-upload-packsandboxes saturate host vCPU or NIC egress bandwidth.
- When to increase vertically (scale up):
stravin_node_cache_bytes_usedstays pinned near the node's NVMe capacity while the cache hit ratio (stravin_node_cache_hits_total / (hits + misses)) drops andstravin_node_s3_pack_fetches_totalrises for active repositories (indicating NVMe working-set thrashing rather than cold traffic).- Frequent
cgroup v2OOM kills or elevatednode.git.upload_packspan durations on large monorepos even when overall node RPS is low.
- When to decrease (scale in / scale down):
- Host CPU < 30%,
stravin_node_cache_bytes_usedcomfortably below NVMe ceiling across the fleet, and p99stravin_node_request_duration_secondswithin SLO for 15–30 minutes.
- Host CPU < 30%,
- How to scale in safely:
- Step down one node at a time (or at most 10% of the fleet) with a pause between removals so rendezvous-remapped repositories re-warm on remaining nodes without triggering a thundering herd of S3
GetObjectcalls. - Drain active
git-upload-packandgit-receive-packstreams before shutting down.
- Step down one node at a time (or at most 10% of the fleet) with a pause between removals so rendezvous-remapped repositories re-warm on remaining nodes without triggering a thundering herd of S3
3. stravin-pack (Horizontal + Vertical)¶
stravin-pack runs out-of-band sharded compaction (Tier 0 streaming merges and Tier 1 deep delta repacks) and delayed garbage collection by claiming DynamoDB manifest shard leases (SHARD#{m}).
- Scaling type: Hybrid (Horizontal up to shard count
M, Vertical for heavy Tier 1 repacks).- Horizontal increases parallel compaction across manifest shards, up to a hard ceiling of the active manifest shard count
M(typically 32–64). Running more workers than dirty shards adds zero throughput and only increases lease contention. - Vertical (higher RAM, CPU, and scratch NVMe per worker) is needed when Tier 1 deep delta compression,
.midx, orcommit-graphbuilds on large repositories exceed single-worker memory or time budgets.
- Horizontal increases parallel compaction across manifest shards, up to a hard ceiling of the active manifest shard count
- When to increase horizontally (scale out):
stravin_pack_uncompacted_packstrends upward faster thanstravin_pack_compaction_cycles_totalclears them.stravin_pack_compaction_lag_secondsbreaches target (Tier 0 packs not consolidating within seconds, riskinggit-upload-packread degradation) whilestravin_pack_lease_contention_totalremains low.
- When to increase vertically (scale up):
stravin_pack_compaction_duration_secondsp99 spikes on individual shards, or workers hit memory/NVMe ceilings during Tier 1 repacks while shard concurrency is already saturated.
- When to decrease (scale in):
stravin_pack_uncompacted_packsandstravin_pack_compaction_lag_secondsremain near baseline for 10–15 minutes, orstravin_pack_lease_contention_totalrises sharply (workers fighting over too few dirty shards).
- How to scale in safely: On
SIGTERM, stop claiming new shard leases, finish any in-progress two-phase manifest swap (Publish→Supersede), and explicitly release held DynamoDB leases before exiting.
4. stravin-relay (stravin-hook in v1.12.x) (Horizontal)¶
In vNext (ADR-0001), stravin-relay (renamed from stravin-hook in Core v1.12.x) is a pure, lightweight transactional outbox relay that tails DynamoDB Streams (Ref History NEW_IMAGE) and publishes Standard Async Event Envelopes onto NATS JetStream (STRAVIN_CORE) completely off the git push path. stravin-relay runs zero Wasm and sends zero external HTTP webhooks (external HTTP delivery scales independently in stravin-webhooks, and any future async post-receive Wasm runner scales as a separate JetStream consumer).
- Scaling type: Horizontal. Scale relay instances up to the active DynamoDB Streams shard count (one active consumer per shard). Because
stravin-relayperforms no outbound internet I/O or Wasm execution, vertical CPU/RAM requirements stay minimal and predictable. - When to increase (scale out):
- DynamoDB Streams iterator age / consumer lag rises continuously (events aging faster than
stravin-relaypublishes them to JetStream). - Relay goroutine/CPU utilization exceeds 70% (
v1.12.xstravin-hook:hook.async.dispatchlatency or outbound webhook retry/DLQ queue depth grows).
- DynamoDB Streams iterator age / consumer lag rises continuously (events aging faster than
- When to decrease (scale in):
- Stream iterator age is near zero and CPU stays low (< 25%) for 10–15 minutes.
- How to scale in safely: Stop polling new stream batches, flush in-flight JetStream publishes (deduplicated via
Nats-Msg-Id), and commit the final DynamoDB Stream sequence checkpoint before terminating. (Inv1.12.x,stravin-hookfinishes in-flight HTTP webhook deliveries before committing its checkpoint.)
5. stravin-ctrl (Fixed HA + Vertical Only)¶
stravin-ctrl orchestrates regional home_region ownership transitions, increments failover_epoch fencing tokens, and runs post-failover S3 HeadObject integrity scrubs and ref rewinds.
- Scaling type: Fixed Active-Passive HA (1 active leader + 1–2 warm standbys); Vertical only.
- Never scale horizontally for throughput. Failover fencing and ref-rewind mutations require single-leader serialization; adding active instances introduces split-brain coordination risk.
- Vertical scaling (more CPU, memory, and network sockets on the leader/standby pair) increases parallel
HeadObjectverification concurrency during disaster failover scrubs.
- When to increase vertically (scale up):
- Periodic failover drills show
ctrl.scrub.regionorctrl.failover.transitionspan durations approaching the RTO budget due to CPU, RAM, or concurrent connection saturation on the leader.
- Periodic failover drills show
- When to decrease vertically (scale down):
- Only after confirming repository count and recent-pack volume fit comfortably within the smaller instance class during a failover drill.
Platform & Foundation Services Scaling (vNext — TBD / Planned)¶
Per ADR-0001 and ADR-0003, platform infrastructure and foundation services scale independently of Core's Git data plane:
| Service | Scaling Type | Primary Scaling Signals | Constraints & Safety Rules |
|---|---|---|---|
NATS JetStream |
Fixed Odd-Quorum Raft + Vertical (3 or 5 pods, R=3) |
Stream storage utilization, JetStream publish/ack p99 latency, consumer pending count | Never HPA-autoscale Raft cluster size. Scale vertically (NVMe PVC IOPS/size, RAM, CPU) or expand storage before adding cluster peers; keep odd quorum (3 or 5). |
Temporal (Run & Gate only) |
Horizontal (Server tiers + Run/Gate workers) | Task-queue backlog, schedule-to-start latency, workflow/activity execution latency | Scale Run and Gate Temporal worker pools independently on their own namespaces (stravin-run, stravin-gate). Core, Review, Index, Webhooks, Auth, and Notify remain permanently Temporal-free. |
stravin-webhooks |
Horizontal (fan-out + delivery workers) | STRAVIN_WEBHOOK_OUTBOX pending lag, outbound HTTP concurrency, per-endpoint retry depth |
Per-endpoint JetStream queues, rate limits, and circuit breakers isolate slow customer endpoints so one broken destination never forces fleet-wide scale-out. |
stravin-auth |
Horizontal (stateless API) + Valkey (independent) | Login/SSO/STS exchange RPS, SCIM/Directory Sync burst rate, RBAC batch filter latency | Strictly off the synchronous Git hot path (stravin-edge verifies cached JWKS locally); Git RPS does not drive stravin-auth scaling. Scale Valkey jti deny-list independently for low-latency write checks. |
stravin-notify |
Horizontal (fan-out/channel workers + WS/SSE gateways) | STRAVIN_NOTIFY_OUTBOX lag, per-channel provider throttling, active WebSocket/SSE connection count |
Isolate external channel workers (email, web_push, slack/teams/discord) from In-App Inbox persistence; scale WS/SSE pods horizontally over Valkey pub/sub. |
Telemetry Signal Quick Reference¶
| Telemetry Signal | Target Service | Scale Direction | Interpretation & Action |
|---|---|---|---|
stravin_edge_request_duration_seconds (p99) high + stravin_node_request_duration_seconds flat |
stravin-edge |
Horizontal Out | Ingress/proxy bottleneck; add stravin-edge replicas. |
stravin_node_request_duration_seconds (p99) + stravin_node_requests_total + CPU > 70% |
stravin-node |
Horizontal Out | Compute/concurrency saturation; add stravin-node replicas to rendezvous ring. |
stravin_hook_wasm_duration_seconds > 15–30 ms or stravin_hook_wasm_verdicts_total{verdict="timeout"} rising |
stravin-node |
Horizontal Out | Tier 1 Wasm bulkhead saturated; add stravin-node replicas (or widen host vCPUs). |
stravin_node_cache_bytes_used near cap + cache hit ratio falling + stravin_node_s3_pack_fetches_total rising |
stravin-node |
Vertical Up (or Out for multi-tenant spread) | NVMe working-set thrashing; upsize NVMe/RAM if single large repos dominate, or add nodes if aggregate tenant count grew. |
stravin_pack_uncompacted_packs & stravin_pack_compaction_lag_seconds rising + low stravin_pack_lease_contention_total |
stravin-pack |
Horizontal Out (up to M) |
Compaction falling behind push rate; add workers up to manifest shard count M. |
stravin_pack_compaction_duration_seconds (p99) high + high per-worker RAM/NVMe |
stravin-pack |
Vertical Up | Single-shard Tier 1 repack is memory/CPU bound; move workers to larger instance class. |
stravin_pack_lease_contention_total rising + low lag |
stravin-pack |
Horizontal In | Excess idle workers contending on leases; remove workers. |
DynamoDB Streams iterator age / JetStream publish lag rising (v1.12.x: hook.async.dispatch backlog) |
stravin-relay (stravin-hook) |
Horizontal Out | Outbox relay falling behind; add consumers up to active DynamoDB Streams shard count. |
ctrl.scrub.region duration approaching RTO during drill |
stravin-ctrl |
Vertical Up | Increase leader/standby CPU/RAM/network; keep active count fixed at 1. |
Anti-Thrashing & Safety Guardrails¶
Do Not Autoscale Compute to Fix Storage Throttling
If stravin_ddb_transact_total{result="throttled"}, stravin_ddb_cas_retries_total, or stravin_s3_origin_fallback_total spikes alongside latency, do not scale out stravin-node or stravin-edge. Adding more writers amplifies retry storms against already-throttled DynamoDB partitions; address table WCU quotas, WarmThroughput, or shard counts (S/M) first.
- Asymmetric cooldown windows: Scale out quickly (1–3 minute sustain window) to protect user-facing Git SLOs; scale in slowly (5–10 minutes for stateless
stravin-edge/stravin-relay/stravin-auth/stravin-webhooks/stravin-notify, 15–30 minutes for warm-cachestravin-node) so brief traffic lulls do not churn NVMe caches. - Step-capped scale-in on
stravin-node: Never remove more than 10% ofstravin-nodereplicas in a single step; verifystravin_node_cache_hits_totalstabilizes before removing the next replica. - Telemetry health fail-safe: Monitor
stravin_otel_dropped_items_totalandotelcol_exporter_enqueue_failed_spans. If telemetry drops spike or Prometheus data goes stale, freeze scale-in actions so autoscalers never downscale on missing metrics. - Minimum floor per region: Maintain at least 2 replicas of
stravin-edgeandstravin-nodeacross distinct Availability Zones in every active region, and 1 active + 1 standby forstravin-ctrl.
Related Documents¶
- Telemetry & Observability — OpenTelemetry Collector pipeline, Prometheus metrics, and cardinality rules referenced by scaling triggers.
- Zero-Downtime Deployment — Ordered rolling and canary deployment waves, graceful drains, and rollback gates across Core daemons and
vNextplatform services. - Performance & Throughput Scaling — DynamoDB WCU/shard math, S3 prefix sharding, and tiered LSM compaction ceilings.
- System Topology & Request Flows — Service roles, rendezvous hashing, and two-phase compaction lifecycles.
- Sandboxed Execution & Multi-Tenancy —
cgroup v2ceilings, NVMe tenant cache quotas, and noisy-neighbor isolation. - ADR-0001: Platform Transport, Events & Webhooks & ADR-0003: Platform Auth & SSO Seam — Platform foundation service boundaries and scaling assumptions.