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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.