API Error Handling with Problem Details (RFC7807-ish)

APIs are easier to operate when errors are structured and consistent. Wrap errors into a problem-details style response with a stable type and request_id so support can quickly trace issues.

Safer HTML Sanitization Pipeline

User content needs defense in depth: markdown rendering + sanitization + link attribute hygiene. Keep the allowed tags list explicit and test it. Don’t trust upstream renderers to be safe by default.

Template rendering with html/template and strict escaping

Even in API-heavy systems, I occasionally render HTML emails or a lightweight admin page. I always use html/template (not text/template) so content is escaped by default, which prevents accidental XSS when variables contain user input. I also keep tem

API monitoring with custom instrumentation

Production visibility requires more than basic request logging. I instrument critical code paths using ActiveSupport::Notifications to publish custom metrics that monitoring services consume. Each instrumented block publishes events with timing data,

Django database connection pooling for performance

Connection pooling reuses database connections instead of creating new ones per request. I use django-db-pool or configure persistent connections with CONN_MAX_AGE. This reduces connection overhead significantly. For high-traffic sites, I set appropri

Rate limiting and API throttling

Rate limiting prevents API abuse and ensures fair resource usage. I implement rate limiting using Bucket4j for token bucket algorithm or Redis for distributed scenarios. Limits apply per user, IP, or API key. HTTP 429 (Too Many Requests) indicates lim

Terraform basics: providers, resources, and state

Terraform is an infrastructure as code (IaC) tool that provisions cloud resources declaratively. Configuration files use HCL (HashiCorp Configuration Language). The provider block configures cloud providers like AWS, GCP, or Azure. resource blocks def

Django debug toolbar for development

Django Debug Toolbar reveals query counts, cache hits, and template rendering time. I add it only in development settings. The toolbar shows all SQL queries which helps identify N+1 problems. I use the profiler panel to find slow code. The cache panel

SwiftUI List with pull-to-refresh and infinite scroll

Lists are fundamental to iOS apps, displaying scrollable collections efficiently. SwiftUI's List or ScrollView with LazyVStack renders items on-demand. I add pull-to-refresh with the .refreshable modifier, calling async refresh logic. For infinite scr

Lazy init of expensive clients with sync.Once

Some dependencies are expensive to initialize (TLS-heavy clients, large config loads, SDKs that fetch metadata). I use sync.Once to ensure initialization happens exactly once, even under concurrent access. The important detail is capturing the initial

ETag + last_modified for expensive Turbo Frame endpoints

Turbo Frames can trigger lots of small requests, so caching matters. For expensive frame endpoints (like an activity panel), I use stale? with an ETag that includes a cache key and the latest update timestamp. If the content hasn’t changed, Rails retu

Turbo Stream broadcasts for real-time collaboration

Broadcasting Turbo Streams via Action Cable enables real-time collaborative features without polling. When a model is created, updated, or destroyed, I broadcast the change to all subscribed users using broadcasts_to or manual broadcast_* methods. Sub