Recipes
Step-by-step solutions for real development tasks.
699 published
Page 3 of 20
Write IAM Policies with Least Privilege Actions
Scope the IAM policy to exact actions and resources so a leaked key can only read one bucket not the whole account.
Make Retries Safe with an Idempotency Key
Accept an idempotency key header so a retried payment request returns the original result instead of charging twice.
Lazy Load Below-the-Fold Images with Native API
Add loading=lazy to offscreen images so the browser defers their fetch until scroll, cutting initial page weight by 60 percent.
Rotate Image Pull Secrets Periodically
Create a new pull secret, patch the service account, and remove the old one so registry credentials rotate without a pod restart storm.
Reconstruct an Incident Timeline from Audit Logs
Query the audit log for all actions in the incident window and produce a timeline so the postmortem has facts not memory.
Add a Covering Index for Hot Query Columns
Include all columns the query reads in the index so the database answers from the index without touching the table.
Create Indexes Concurrently Without Locking
Use CREATE INDEX CONCURRENTLY so the table stays available for reads and writes during the index build.
Infinite Scroll with Intersection Observer
Observe a sentinel element at the list bottom and load more when it enters the viewport so there are no page buttons and scrolling is seamless.
Terminate TLS at the Ingress Controller
Configure the ingress with a TLS secret so the controller terminates TLS and backend pods receive plain HTTP on localhost.
Run a Migration in an Init Container
Put the database migration in an init container so the app container starts only after the schema is at the expected version.
Validate All Inputs with a Zod Schema
Parse every request body and query param through a Zod schema so malformed input is rejected with a 400 before it reaches the handler.
Run Integration Tests Against docker-compose
Spin up dependencies in compose, run integration tests against them, and tear down so tests run identically locally and in CI.
Set Job Backoff Limit for Retry Exhaustion
Configure backoffLimit and activeDeadlineSeconds so a failing job retries 3 times then stops instead of looping forever.
Index JSONB Columns with GIN for Fast Lookups
Create a GIN index on the JSONB path so queries like data->>'type' = 'x' use the index instead of a sequential scan.
Issue Short-Lived JWT Tokens with Refresh
Set JWT expiry to 15 minutes and use a refresh token rotation scheme so a stolen access token is useless within a quarter hour.
Enable Automatic KMS Key Rotation
Turn on automatic rotation for the KMS key so the key material changes yearly without re-encrypting existing data.
Reduce Lambda Cold Starts with Provisioned Concurrency
Set provisioned concurrency on the alias so the first N invocations have no init delay and p99 latency drops.
Ramp Load with k6 Stages Profile
Define a k6 stage profile that ramps from 10 to 500 virtual users over 5 minutes so the breaking point is visible in the metrics.
Set Log Aggregation Retention by Index
Configure hot-warm-cold retention so recent logs are fast to query, old logs are cheap, and expired logs are deleted automatically.
Redact PII from Logs Before Shipping
Pipe logs through a redaction filter that masks email and phone fields so PII never reaches the aggregation system.
Sample High-Volume Logs to Control Cost
Apply a 10 percent sampling rate to debug logs so the volume is manageable but errors are always logged at 100 percent.
Refresh a Materialized View Concurrently
Refresh the materialized view concurrently so readers never block and the dashboard stays available during the refresh.
Memoize Expensive Pure Functions with Cache Key
Cache the result of a pure sort or filter by its input hash so repeated calls with the same data return instantly.
Batch Pull Requests Through a Merge Queue
Enable a GitHub merge queue so multiple pull requests are batched and validated together before landing on main.
Configure Histogram Buckets for Latency SLOs
Set histogram bucket boundaries around the SLO threshold so p99 is accurate and not rounded into the wrong bucket.
Run a Zero-Downtime Migration in Three Phases
Split the migration into expand, migrate, and contract phases so the old and new code run side by side during the transition.
Trap Focus Inside a Modal Dialog
Move focus to the modal on open, cycle within, and restore to the trigger on close so keyboard users cannot tab behind the overlay.
Build Multi-Arch Images with buildx
Use docker buildx with linux/amd64 and linux/arm64 platforms so the image runs on both Intel nodes and Graviton instances.
Gate on Mutation Testing Score
Run a mutation testing tool on new code so a high line coverage that hides untested logic is caught before merge.
Enforce Resource Quotas per Namespace
Set CPU and memory quotas on each namespace so a team cannot accidentally consume all cluster resources.
Default-Deny Network Traffic with NetworkPolicy
Apply a default-deny ingress policy so pods are isolated by default and only explicit allow rules open connections.
Link Alerts to Runbooks for On-Call Guidance
Attach a runbook URL to every alert so the on-call engineer sees the exact steps to diagnose and mitigate, not just a metric name.
Use Optimistic Locking with a Version Column
Add a version column and check it on update so concurrent edits are detected and the last writer gets a 409 not a silent overwrite.
Apply Optimistic UI Updates with Rollback
Update the UI immediately, send the request, and roll back on error so the interaction feels instant and stays correct.
Route Logs Through an OTel Collector Pipeline
Send logs to the OpenTelemetry Collector which batches, transforms, and exports to multiple backends without app code changes.
Publish Events via the Outbox Pattern
Write the event to an outbox table in the same transaction as the business write so the event is not lost if the broker is down.