Recipes

Step-by-step solutions for real development tasks.

699 published

Page 2 of 20

Follow System Dark Mode Preference with CSS

Use prefers-color-scheme media query and a manual toggle that persists to localStorage so the theme follows the OS unless overridden.

~15 min
frontend · dark-mode · css

Version Dashboards as Code with Grafana

Define dashboards in JSON committed to the repo so changes are reviewed and reproducible, not lost in a UI edit.

~20 min
observability · dashboards · grafana

Migrate Data in Batches with a Cursor

Process records in batches of 1000 using a cursor so a 10 million row migration does not blow up memory or lock the table.

~30 min
database · migration · batch

Enforce a Data Retention Policy with TTL Jobs

Schedule a job that deletes records past their retention window so the database does not hold data longer than the policy allows.

~20 min
security · retention · compliance

Debounce Search Input to Reduce API Calls

Wrap the search handler in a 300ms debounce so typing five characters fires one request not five.

~15 min
performance · frontend · debounce

Defer Non-Critical JS to After Interactive

Add defer to analytics and widget scripts so they do not block parsing and the page reaches interactive 800ms sooner.

~10 min
performance · frontend · defer

Audit Dependency Licenses Against an Allowlist

Run a license scanner on every dependency so a GPL-licensed transitive package is caught before it ships in a proprietary product.

~20 min
security · licensing · dependencies

Collect Deploy Timing Metrics per Stage

Instrument the deploy pipeline to emit per-stage duration metrics so regressions in deploy time are visible on a dashboard.

~20 min
ci · metrics · deployment

Automate Deployment Rollback on Failed Health Check

Wire a rollback step into the deploy pipeline that triggers when the post-deploy health check fails beyond a retry threshold.

~30 min
ci · deployment · kubernetes

Propagate Distributed Trace Context Across Hops

Inject the traceparent header on every outbound call so a request is traceable across service boundaries.

~20 min
observability · tracing · otel

Switch to a Distroless Base Image for Security

Replace debian with gcr.io/distroless so the image has no shell, no package manager, and a 90 percent smaller attack surface.

~20 min
kubernetes · security · distroless

Spin Up a Dynamic Review Environment per PR

Create an ephemeral namespace per pull request so reviewers can test the change before merge, then tear it down on close.

~35 min
ci · kubernetes · review-env

Build a Dynamic Matrix Across Node Versions

Generate a CI matrix from the lockfile so every supported runtime is tested without hardcoding version numbers in the workflow.

~25 min
ci · testing · matrix

Auto-Scale DynamoDB Read and Write Capacity

Enable autoscaling on the table with a target utilization of 70 percent so a traffic spike does not throttle reads or writes.

~20 min
cloud · dynamodb · autoscaling

Handle EC2 Spot Interruption Notices Gracefully

Poll the instance metadata for an interruption notice and drain gracefully so a spot instance is not killed mid-request.

~25 min
cloud · ec2 · spot

Size ECS Fargate Tasks for Cost and Headroom

Set the task CPU and memory to the p95 usage plus 20 percent headroom so tasks are not throttled or over-provisioned.

~20 min
cloud · ecs · fargate

Convert an Enum to a Lookup Table

Replace the enum with a foreign key to a lookup table so new values are added with INSERT not a migration.

~25 min
database · refactor · lookup

Protect Deployment Environments with Required Reviewers

Configure environment protection rules so production deploys require a human reviewer and a deployment branch.

~20 min
ci · security · environments

Recover from Render Errors with an Error Boundary

Add an error boundary that shows a fallback and a retry button so a null pointer in one widget does not blank the whole page.

~20 min
frontend · react · error-boundary

Group Errors by Fingerprint Not Message

Hash the stack trace frames into a fingerprint so the same error with different variable values groups together.

~15 min
observability · errors · grouping

Apply Expand-Contract for Backward-Compatible Schema

Add the new column, backfill it, switch reads, then drop the old column so no deploy sees a missing or extra column.

~25 min
database · migration · expand-contract

Choose Fakes Over Mocks for Stable Tests

Replace brittle mock call-count assertions with a fake implementation that captures state so tests survive refactors of the call pattern.

~20 min
testing · mocking · fakes

Quarantine Flaky Tests with Auto-Retry

Detect tests that fail intermittently, quarantine them in a separate suite, and open an issue so they are fixed not ignored.

~20 min
testing · flaky · quarantine

Use font-display Swap to Avoid FOIT

Set font-display: swap so text renders immediately in a fallback and swaps to the custom font when it loads, eliminating invisible text.

~10 min
performance · fonts · fouf

Validate Forms Progressively from Blur to Submit

Validate on blur, then on change after first error, then on submit so the user gets feedback without aggressive red fields on first focus.

~20 min
frontend · forms · validation

Compare Output Against a Golden Master File

Record a golden master output from a stable build and diff future runs against it so unintended output changes fail the test.

~25 min
testing · golden · regression

Limit GraphQL Query Depth to Prevent Nested Abuse

Set a max depth of 7 so a malicious query like { user { posts { user { posts ... } } } } is rejected before execution.

~20 min
api · graphql · security

Fix GraphQL N+1 with DataLoader

Batch per-request data loads with DataLoader so a list of 50 items fetches their authors in one query not 50.

~25 min
api · graphql · dataloader

Propagate gRPC Deadlines Across Service Hops

Set a deadline on the client and propagate it so a downstream call does not hang past the upstream caller's timeout.

~20 min
api · grpc · deadline

Automate a Response to GuardDuty Findings

Send GuardDuty findings to an EventBridge rule that isolates the instance so a compromised host is quarantined within minutes.

~30 min
cloud · guardduty · automation

Negotiate Brotli Over Gzip for Better Ratio

Check Accept-Encoding and serve Brotli when available so text assets are 20 percent smaller than gzip.

~15 min
performance · compression · brotli

Scale on a Custom Metric with HPA

Configure a Horizontal Pod Autoscaler on a custom queue depth metric so the deployment scales with backlog not just CPU.

~25 min
kubernetes · hpa · autoscaling

Submit HSTS to the Browser Preload List

Set Strict-Transport-Security with preload and submit the domain so future browsers refuse HTTP connections without a first-visit redirect.

~15 min
security · hsts · tls

Use HTTP/2 Server Push for Critical Resources

Push the CSS and font before the browser parses the HTML so the waterfall collapses and LCP drops by 400ms.

~20 min
performance · http2 · server-push

Lazy Load Locale Bundles on Language Switch

Dynamically import the locale bundle on switch so the initial bundle is not bloated with translations for every language.

~20 min
frontend · i18n · lazy-load

Scan IaC for Misconfigurations with tfsec

Run a static analyzer on Terraform so an S3 bucket without encryption or a security group open to 0.0.0.0/0 is caught before apply.

~20 min
security · iac · terraform