Postgres transaction pattern with pgx: defer rollback, commit explicitly

The most common transaction bug I see is forgetting to roll back on early returns. With pgx, I like the “defer rollback” pattern: start the transaction, defer tx.Rollback(ctx), then call tx.Commit(ctx) only on success. Rollback after a successful comm

Exponential backoff with jitter for retries

Retries are dangerous when they synchronize; that’s how you turn a minor outage into a stampede. I implement exponential backoff with jitter so clients spread out naturally. The Retry helper takes a shouldRetry predicate and always checks ctx.Done() b

Token bucket rate limiter for outbound calls

Outbound rate limiting is one of those “quiet reliability” features: customers rarely notice it until it’s missing. I prefer a simple token bucket using golang.org/x/time/rate because it’s well-tested and easy to reason about. Each call waits for a to

Bounded worker pool with backpressure

I avoid unbounded goroutines when processing queues; they look fine in staging and then blow up under a burst. This worker pool keeps a fixed number of workers and a bounded channel for jobs, which creates backpressure by design. The Submit call respe

Fan-out with errgroup and shared cancellation

When you need to call multiple downstream systems, errgroup is a great way to express “do these in parallel, cancel on first failure.” The key is using errgroup.WithContext, not a plain WaitGroup, so the group can propagate cancellation. Each goroutin

Graceful shutdown: draining HTTP + background workers

A clean shutdown is part of reliability, not an afterthought. The pattern I like is: (1) start servers and workers, (2) listen for SIGINT/SIGTERM, (3) call Shutdown with a deadline, and (4) wait for background goroutines to finish. http.Server.Shutdow

HTTP handler with timeouts, request IDs, and context cancellation

I treat context.Context as the contract between the edge and everything downstream. The pattern here starts by creating a per-request timeout using context.WithTimeout, then storing a requestID in the context so logs and traces can correlate without p

Django deployment checklist and production settings

Deploying Django to production requires many configuration changes. I set DEBUG=False and configure ALLOWED_HOSTS. Security settings include SECURE_SSL_REDIRECT, SESSION_COOKIE_SECURE, CSRF_COOKIE_SECURE. I use environment variables for secrets. Stati

Django haystack for advanced search

Haystack provides unified search across backends (Elasticsearch, Solr, Whoosh). I define search indexes mapping models to searchable fields. It handles full-text search, faceting, and highlighting. The SearchQuerySet API is similar to Django's ORM. I

Django REST Framework schema and documentation

DRF auto-generates API schemas and documentation. I use drf-spectacular for OpenAPI 3.0 schemas. The schema describes endpoints, parameters, and responses. I customize with decorators like @extend_schema. Interactive docs via Swagger UI or ReDoc let d

Django database read-write split with routers

Database routers enable read-write splitting for scaling. I direct reads to replicas and writes to primary. The router examines hints and model to make routing decisions. For read-heavy apps, this distributes load across multiple databases. I use usin

Django custom user model best practices

Extending Django's user model should be done early in projects. I use AbstractBaseUser for full control or AbstractUser to extend the default. Setting AUTH_USER_MODEL points Django to my custom model. I add fields like phone, avatar, or preferences. F