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.

~25 min
cloud · iam · security

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.

~20 min
api · idempotency · retry

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.

~10 min
performance · images · lazy-load

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.

~25 min
kubernetes · secrets · rotation

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.

~25 min
observability · incident · timeline

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.

~20 min
performance · database · indexing

Create Indexes Concurrently Without Locking

Use CREATE INDEX CONCURRENTLY so the table stays available for reads and writes during the index build.

~20 min
database · index · concurrent

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.

~20 min
frontend · scroll · intersection

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.

~15 min
kubernetes · ingress · tls

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.

~20 min
kubernetes · init · migration

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.

~20 min
security · validation · zod

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.

~30 min
testing · integration · docker

Set Job Backoff Limit for Retry Exhaustion

Configure backoffLimit and activeDeadlineSeconds so a failing job retries 3 times then stops instead of looping forever.

~15 min
kubernetes · job · retry

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.

~20 min
database · jsonb · gin

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.

~25 min
security · jwt · tokens

Enable Automatic KMS Key Rotation

Turn on automatic rotation for the KMS key so the key material changes yearly without re-encrypting existing data.

~15 min
cloud · kms · rotation

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.

~20 min
cloud · lambda · cold-start

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.

~35 min
testing · load · k6

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.

~15 min
observability · logging · retention

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.

~20 min
observability · logging · pii

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.

~15 min
observability · logging · sampling

Refresh a Materialized View Concurrently

Refresh the materialized view concurrently so readers never block and the dashboard stays available during the refresh.

~20 min
database · materialized-view · 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.

~15 min
performance · memoization · caching

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.

~15 min
ci · github · workflow

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.

~20 min
observability · metrics · histogram

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.

~30 min
database · migration · zero-downtime

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.

~20 min
frontend · accessibility · focus-trap

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.

~25 min
kubernetes · multi-arch · buildx

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.

~40 min
testing · mutation · quality

Enforce Resource Quotas per Namespace

Set CPU and memory quotas on each namespace so a team cannot accidentally consume all cluster resources.

~15 min
kubernetes · quota · governance

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.

~20 min
kubernetes · networkpolicy · security

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.

~15 min
observability · alerting · runbook

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.

~20 min
database · optimistic-lock · concurrency

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.

~20 min
frontend · optimistic · ui

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.

~25 min
observability · otel · collector

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.

~25 min
api · outbox · events