Recipes

Step-by-step solutions for real development tasks.

699 published

Page 19 of 20

Roll Out Config Changes Without Restarting Everything

Version ConfigMaps, roll pods gradually with maxUnavailable 0, and keep serving when a configuration key is missing.

~30 min
kubernetes · config · deployment

Apply a Zero-Downtime PostgreSQL Column Migration

Use the expand-contract pattern with lock timeouts, batched backfills, and a bidirectional trigger to rename a column without breaking rolling deploys.

~50 min
postgresql · migrations · zero-downtime

Add API Deprecation Headers

Announce deprecation with Deprecation, Sunset, and Link headers, keep clients informed, and remove the old endpoint only after the sunset date.

~30 min
api · lifecycle · operations

Add an Append-Only Audit Log

Record who changed which record, when, and from where in an append-only table written in the same transaction as the business change.

~35 min
database · audit · security

Warm Critical Cache Keys Before Traffic

Preload high-value keys after a deploy or cache flush, coalesce the warm-up, and verify hit ratio without turning startup into a stampede.

~30 min
caching · performance · operations

Add a Circuit Breaker Around a Dependency

Wrap a flaky dependency with a closed/open/half-open circuit breaker, cap failures, allow one probe, and expose state for metrics.

~30 min
resilience · nodejs · reliability

Set a Connection Pool Budget

Size database pools from the server's connection limit, reserve capacity for operations, and verify the total across replicas and background workers.

~25 min
database · capacity · reliability

Add a Dead-Letter Queue Policy

Bound retries, route poison messages to a DLQ with context, alarm on depth and age, and document a safe replay procedure.

~25 min
messaging · reliability · operations

Add a Dependency Lockfile Audit

Audit the committed lockfile for known vulnerabilities, fail CI on high severity, and remediate through version updates rather than blanket overrides.

~25 min
security · supply-chain · ci-cd

Add an Error-Budget Burn-Rate Alert

Alert on how fast the error budget is being consumed with multi-window burn rates, instead of waiting for a monthly SLO to be exhausted.

~35 min
reliability · observability · alerting

Add Event Schema Versioning with an Envelope

Wrap events in a versioned envelope, keep payload changes compatible, and upcast old versions when reading so historical events remain replayable.

~35 min
events · data-integration · contracts

Add Fencing Tokens to Protected Writes

Attach a monotonically increasing token to every write and reject older tokens at storage so a paused lock holder cannot overwrite newer data.

~30 min
distributed-systems · locking · data-consistency

Add a Graceful Degradation Fallback

Serve a stale or reduced response when a dependency fails, mark it explicitly, and verify that the fallback cannot mask a data-integrity problem.

~30 min
resilience · api · user-experience

Add a Graceful Shutdown Handler

Handle SIGTERM in a Node.js service by failing readiness, stopping new connections, draining in-flight requests, and forcing exit after a deadline.

~25 min
nodejs · operations · deployment

Add HTTP Strict Transport Security

Send a Strict-Transport-Security header only over HTTPS, start with a short max-age, verify it at the edge, and understand the commitment of preload.

~15 min
security · http · tls

Add an Idempotent Consumer Handler

Record message ids in the same transaction as the business change so at-least-once delivery produces a single effect after retries and restarts.

~30 min
messaging · idempotency · reliability

Add an Idempotent Webhook Handler

Verify webhook signatures over the raw body, deduplicate event ids in a transaction, and return quickly so provider retries cannot apply the same event twice.

~30 min
webhooks · idempotency · security

Set Kubernetes Resource Requests and Limits

Choose CPU and memory requests from measured usage, set limits that prevent noisy neighbors, and verify QoS, throttling, and OOM behavior.

~30 min
kubernetes · capacity · reliability

Add Latency Fault Injection for Resilience Tests

Inject bounded latency behind an explicit test flag, verify timeouts and fallbacks, and guarantee the injection is disabled outside test environments.

~30 min
resilience · testing · operations

Add Load-Shedding Middleware

Reject new work with 503 and Retry-After when in-flight requests exceed a measured limit, keeping accepted requests within their latency target.

~25 min
resilience · nodejs · capacity

Add an OpenAPI Contract Test

Lint the OpenAPI document in CI, exercise every endpoint with Schemathesis against a test server, and fail on responses that violate the contract.

~35 min
api · testing · openapi

Add OpenTelemetry Tracing to a Node.js Service

Initialize the OpenTelemetry SDK before the app loads, instrument HTTP and database calls, export traces, and shut down cleanly.

~40 min
observability · tracing · nodejs

Add Optimistic Locking with a Version Column

Prevent lost updates by adding a version column, updating with a version predicate, and returning 409 when two writers modify the same row concurrently.

~25 min
database · concurrency · postgresql

Add an Outbox Relay

Publish events reliably by writing them to an outbox in the business transaction, then relaying unpublished rows with retries and idempotent consumers.

~40 min
messaging · data-consistency · reliability

Add a Performance Budget to CI

Set gzip size limits for entry bundles, fail pull requests that exceed them, and keep the budget visible as a review signal rather than a surprise outage.

~25 min
performance · ci-cd · frontend

Add PostgreSQL Slow Query Logging

Enable slow query logging with a measured threshold, use pg_stat_statements for aggregates, and analyze plans without logging sensitive bind values.

~25 min
database · postgresql · observability

Add Rate Limiting Middleware

Add a fixed-window rate limiter to an Express service, return 429 with Retry-After, and understand when an in-memory limiter stops being correct.

~25 min
security · rate-limiting · nodejs

Coalesce Concurrent Requests for the Same Key

Merge simultaneous cache misses for one key into a single origin call, share the result, and clean up the in-flight entry so retries are possible.

~25 min
caching · performance · concurrency

Add a Request Timeout Wrapper

Enforce a per-request deadline in Node.js, propagate cancellation to downstream calls, and return a clear 503 instead of holding connections open.

~20 min
nodejs · http · reliability

Generate and Scan an SBOM in CI

Produce a software bill of materials for every build, scan it for known vulnerabilities, retain it with the release, and fail the pipeline on high-severity findings.

~30 min
supply-chain · ci-cd · security

Add an SLO Dashboard

Define a request success SLI, record it with Prometheus rules, and chart the SLO target, current attainment, and remaining error budget.

~40 min
observability · reliability · metrics

Add Structured JSON Logging

Replace ad-hoc console output with structured JSON logs that carry request ids, status, latency, and redacted headers for reliable production debugging.

~20 min
observability · logging · nodejs

Add a Test Data Builder

Replace ad-hoc test fixtures with a builder that has valid defaults, explicit overrides, and small factory functions for related objects.

~25 min
testing · maintainability · typescript

Configure Redis Memory and Eviction Policy

Set a memory ceiling and an eviction policy that matches the data's role, monitor evictions, and prevent Redis from silently deleting queues or sessions.

~25 min
redis · caching · operations

Pin GitHub Actions by Commit SHA

Replace mutable action tags with full commit SHAs, keep the version in a comment, and let Dependabot update pins without reopening a supply-chain hole.

~25 min
security · ci-cd · supply-chain

Verify Database Backups by Restoring Them

Prove a PostgreSQL backup is usable by restoring it into an isolated database, comparing row counts and checksums, and recording the recovery time.

~45 min
database · backup · operations