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.
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.
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.
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.
Debounce Search Input to Reduce API Calls
Wrap the search handler in a 300ms debounce so typing five characters fires one request not five.
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.
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.
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.
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.
Propagate Distributed Trace Context Across Hops
Inject the traceparent header on every outbound call so a request is traceable across service boundaries.
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.
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.
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.
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.
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.
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.
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.
Protect Deployment Environments with Required Reviewers
Configure environment protection rules so production deploys require a human reviewer and a deployment branch.
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.
Group Errors by Fingerprint Not Message
Hash the stack trace frames into a fingerprint so the same error with different variable values groups together.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Negotiate Brotli Over Gzip for Better Ratio
Check Accept-Encoding and serve Brotli when available so text assets are 20 percent smaller than gzip.
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.
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.
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.
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.
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.