
Idempotency Keys in Practice: Making Retries Safe
How to design and implement idempotency keys so retried requests never double-charge, double-send, or double-create resources.
Tags
66 articles

How to design and implement idempotency keys so retried requests never double-charge, double-send, or double-create resources.

Why most async TypeScript code ignores cancellation entirely, and how to build composable, leak-free cancellation with AbortController.

Use TypeScript template literal types to encode event names, route patterns, and permission sets directly into your type system — no runtime checks, no string drift.

How to add fields, rename properties, and restructure events in async systems without coordinating deployments or silently breaking downstream consumers.

When a cache entry expires under high traffic, dozens of requests race to rebuild it simultaneously — here's how inflight request deduplication collapses that stampede into a single upstream call.

Postgres has a powerful built-in full-text search engine using tsvector, tsquery, and GIN indexes — no Elasticsearch cluster required for most applications.

Stop loading entire result sets into memory: how Node.js streams and async generators let you process millions of records without blowing the heap.

Stop racing conditions in distributed systems: a practical guide to implementing distributed locks with Redis and PostgreSQL advisory locks in Node.js.

TypeScript's satisfies operator validates that a value matches a type while preserving literal inference — here's why that distinction matters and where to apply it.

Replace Node's stringly-typed EventEmitter with a generic typed alternative that catches event name typos and payload mismatches at compile time.

Why job queues and database state machines break down for complex multi-step processes, and how durable execution with Temporal gives you workflows that survive crashes, retries, and deployments.

Unbounded Promise.all is a silent OOM killer — here's how to build semaphores, throttled queues, and stream backpressure into your Node.js applications.

N+1 isn't an ORM problem — learn how to implement the DataLoader batching pattern in TypeScript to collapse redundant data fetches across any data source, including microservices.

How the transactional outbox pattern eliminates the dual-write problem and guarantees reliable event publishing without coupling your database to your message broker.

Use AsyncLocalStorage to propagate request-scoped context — trace IDs, user sessions, tenant data — through async call stacks without threading values through every function signature.

Eliminate a whole class of runtime bugs by teaching TypeScript's type system the difference between a UserId and an OrderId — even when both are strings under the hood.

Stop letting your API spec drift from your implementation — define the contract first, generate types for both sides, and let the compiler catch the gaps.

Stop bolting middleware onto frameworks and start building type-safe, composable pipeline primitives you can test in isolation and reason about at a glance.

TypeScript's type system stops at compile time — Zod closes the gap by validating data at the runtime boundaries where it actually matters.

Server Actions bring form handling and mutations back to the server in Next.js — here's how to use them well, what to avoid, and how to build patterns that scale.

Replace boolean flag spaghetti with finite state machines: a TypeScript-first approach to UI states that makes impossible states impossible by construction.

Learn how to use Node.js worker threads to handle CPU-intensive tasks without blocking the event loop, with thread pooling and type-safe messaging patterns.

Move beyond try-catch soup: discriminated unions, Result types, and error boundaries that make TypeScript codebases more reliable and maintainable.

A comprehensive guide to designing and building scalable, production-ready APIs using Next.js Route Handlers with TypeScript, validation, and error handling patterns.

Advanced TypeScript patterns I rely on daily — discriminated unions, branded types, the builder pattern, and utility types that make large codebases safer and more maintainable.

Implement dependency injection in TypeScript using constructor injection, factory functions, DI containers, and module-level composition patterns that improve testability and decouple components without framework lock-in.

Build reliable end-to-end test suites with Playwright using page object models, test isolation, network interception, visual regression testing, and CI integration patterns that catch real user-facing bugs without flaky failures.

Build real-time data pipelines using Apache Kafka with TypeScript consumers and producers, covering partitioning strategies, consumer groups, exactly-once semantics, and dead letter queues for reliable event streaming.

Create professional command-line tools with TypeScript that feature argument parsing, interactive prompts, progress indicators, and structured output, using Commander.js and supporting libraries for a polished developer experience.

A practical guide to achieving end-to-end type safety in GraphQL applications using schema-first code generation, covering resolver typing, client-side query types, and eliminating runtime type mismatches between frontend and backend.

A hands-on guide to managing cloud infrastructure with Pulumi and TypeScript, covering resource composition, state management, secrets handling, and testing infrastructure code with real programming language features.

A complete tutorial on building end-to-end type-safe APIs using tRPC with Next.js App Router, covering router setup, middleware chains, input validation, and real-time subscriptions.

A practical comparison of Pulumi and Terraform for infrastructure as code, demonstrating how general-purpose languages enable abstractions, testing, and composition patterns that HCL cannot express.

Build a production-ready real-time notification system using Server-Sent Events and WebSockets with TypeScript, covering message delivery guarantees, client reconnection, notification persistence, and read-state tracking.

Implement hexagonal architecture with concrete TypeScript examples showing how ports define business contracts, adapters handle infrastructure, and dependency inversion keeps the domain layer testable and framework-independent.

Systematic prompt engineering patterns for production LLM applications including structured output extraction, chain-of-thought reasoning, few-shot calibration, prompt versioning, and automated evaluation pipelines.

Step-by-step tutorial for building a professional CLI tool in Node.js with argument parsing, interactive prompts, colored output, progress indicators, configuration files, and cross-platform publishing to npm.

Learn how property-based testing generates hundreds of random inputs to verify code invariants, catching edge cases that hand-written example tests overlook with practical patterns in TypeScript using fast-check.

Walk through building a type-safe form library in TypeScript with runtime validation, field-level error tracking, dirty state management, and a composable API that catches form errors at compile time.

Implement clean architecture patterns that separate business logic from infrastructure concerns, making applications testable, maintainable, and adaptable to changing requirements or technology choices.

Build a code generator that reads OpenAPI specifications and produces fully typed TypeScript API clients with request validation, error handling, and automatic type inference.

Build robust error boundary strategies that catch failures gracefully, provide meaningful fallbacks, report actionable diagnostics, and prevent one broken component from crashing the entire application.

Walk through building a Markdown parser step by step, covering lexical analysis, AST construction, and HTML rendering to understand how text processing engines work under the hood.

How to build custom ESLint rules for your team's conventions — covering AST selectors, rule testing, auto-fixers, and publishing a shared plugin that enforces patterns your default linter cannot catch.

A step-by-step tutorial for building a GraphQL server with TypeScript — covering schema design, resolvers, dataloaders for N+1 prevention, authentication, error handling, and deployment patterns.

A developer-friendly introduction to compiler fundamentals — covering lexing, parsing, ASTs, and code generation with practical examples that help you write better code, build tooling, and understand language features.

A step-by-step tutorial for building rate limiters using the token bucket, sliding window, and fixed window algorithms — with TypeScript implementations, Redis integration, and production deployment patterns.

How to implement the saga pattern to manage distributed transactions across microservices — comparing orchestration versus choreography approaches with practical TypeScript examples and compensation logic.

A step-by-step tutorial for building an event-driven microservice using Node.js, RabbitMQ, and TypeScript — covering event publishing, consumption, dead letter queues, and idempotent processing.

How to implement hexagonal architecture (ports and adapters) in a real application — separating business logic from infrastructure with clear boundaries, dependency inversion, and testable core domains.

A step-by-step tutorial for building a URL shortener service with short code generation, redirect handling, click analytics, and rate limiting — covering the full system design from database schema to API.

A practical introduction to recommendation systems — covering collaborative filtering, content-based filtering, and hybrid approaches with TypeScript implementations developers can understand and adapt.

A step-by-step tutorial for building a Chrome/Firefox browser extension using TypeScript — covering the manifest file, content scripts, background service workers, popup UI, and messaging between contexts.

A step-by-step tutorial for building a live-updating dashboard using WebSockets — covering server setup, client connection management, data streaming, reconnection logic, and scaling considerations.

A practical introduction to reinforcement learning concepts — agents, environments, rewards, and policies — with TypeScript examples that map RL ideas to problems developers already understand.

How to design a plugin system that lets users extend your application without modifying its core — covering plugin interfaces, lifecycle hooks, dependency resolution, and sandboxing.

A deep dive into async iterators and generators in JavaScript — covering for-await-of loops, async generator functions, backpressure handling, and real-world streaming patterns.

How full-text search engines work internally — covering tokenization, inverted indexes, TF-IDF scoring, and building a working search engine in TypeScript step by step.

How property-based testing finds edge cases your unit tests miss — a practical guide using fast-check to generate thousands of test inputs and verify invariants automatically.

A step-by-step guide for migrating existing JavaScript projects to TypeScript without stopping feature development — covering configuration, strict mode adoption, and team workflows.

How to design custom React hooks that are truly reusable — covering composition patterns, testing strategies, state encapsulation, and common anti-patterns to avoid.

A complete guide to building, testing, and distributing a Node.js CLI tool — covering argument parsing, interactive prompts, output formatting, and npm publishing.

Practical functional programming patterns for TypeScript that improve code clarity without requiring a complete paradigm shift.

A practical guide to TypeScript generics that takes you from basic type parameters to advanced conditional types and utility patterns.

Stop scattering process.env calls across your codebase — validate, type, and centralize environment configuration for safer deployments.

Dependency injection doesn't require a framework or decorators — here's how to apply it in TypeScript with simple patterns that make code testable and flexible.