This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- event_store schema | |
| CREATE TABLE events ( | |
| id BIGSERIAL PRIMARY KEY, | |
| aggregate_id UUID NOT NULL, | |
| aggregate_type TEXT NOT NULL, | |
| event_type TEXT NOT NULL, | |
| sequence_num INT NOT NULL, | |
| payload JSONB NOT NULL, | |
| occurred_at TIMESTAMPTZ NOT NULL DEFAULT now(), | |
| UNIQUE (aggregate_id, sequence_num) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package sharding | |
| import "fmt" | |
| const shardCount = 4 | |
| const rangeSize = 1_000_000 | |
| // RangeSharder routes based on numeric ID ranges. | |
| type RangeSharder struct { | |
| shards []string // DSN per shard |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func deepHealthHandler(db *sql.DB, cache *redis.Client) http.HandlerFunc { | |
| return func(w http.ResponseWriter, r *http.Request) { | |
| ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second) | |
| defer cancel() | |
| type check struct { | |
| name string | |
| fn func() error | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # policies/myapp.hcl | |
| path "secret/data/myapp/*" { | |
| capabilities = ["read", "list"] | |
| } | |
| path "auth/token/renew-self" { | |
| capabilities = ["update"] | |
| } | |
| path "sys/leases/renew" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: apps/v1 | |
| kind: Deployment | |
| metadata: | |
| name: backend-v1 | |
| namespace: production | |
| spec: | |
| replicas: 2 | |
| selector: | |
| matchLabels: | |
| app: backend |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| import httpx | |
| async def fetch_user(client: httpx.AsyncClient, user_id: int) -> dict: | |
| response = await client.get(f"https://api.internal/users/{user_id}") | |
| response.raise_for_status() | |
| return response.json() | |
| async def fetch_permissions(client: httpx.AsyncClient, user_id: int) -> list: | |
| response = await client.get(f"https://api.internal/permissions/{user_id}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TABLE events_2026_01 PARTITION OF events | |
| FOR VALUES FROM ('2026-01-01') TO ('2026-02-01'); | |
| CREATE TABLE events_2026_02 PARTITION OF events | |
| FOR VALUES FROM ('2026-02-01') TO ('2026-03-01'); | |
| CREATE TABLE events_2026_03 PARTITION OF events | |
| FOR VALUES FROM ('2026-03-01') TO ('2026-04-01'); | |
| -- Each partition gets its own indexes. PostgreSQL 11+ propagates these |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # inject-latency.sh — add 200ms ± 50ms jitter to egress on eth0 | |
| # Requires: iproute2, root or CAP_NET_ADMIN | |
| IFACE="${1:-eth0}" | |
| DELAY_MS="${2:-200}" | |
| JITTER_MS="${3:-50}" | |
| DURATION_S="${4:-60}" | |
| echo "[chaos] Injecting ${DELAY_MS}ms ± ${JITTER_MS}ms on ${IFACE} for ${DURATION_S}s" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # prometheus/recording_rules.yml | |
| groups: | |
| - name: slo_availability | |
| interval: 30s | |
| rules: | |
| - record: job:http_requests_total:success_rate5m | |
| expr: | | |
| sum(rate(http_requests_total{status!~"5.."}[5m])) by (job) | |
| / | |
| sum(rate(http_requests_total[5m])) by (job) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TABLE saga_log ( | |
| id BIGSERIAL PRIMARY KEY, | |
| saga_id UUID NOT NULL, | |
| state TEXT NOT NULL, | |
| payload JSONB, | |
| created_at TIMESTAMPTZ NOT NULL DEFAULT now() | |
| ); | |
| CREATE INDEX idx_saga_log_saga_id ON saga_log(saga_id); |