Guide
Premium
Intermediate
Real Projects

Row-Level Security in PostgreSQL: Multi-Tenant Isolation You Can't Forget

A complete guide to moving the tenant filter out of your code and into PostgreSQL with Row-Level Security: why the app must never connect as the table owner, ENABLE vs FORCE, RESTRICTIVE policies as a guardrail beneath permissive ones, USING vs WITH CHECK, and how to propagate the tenant with transactional set_config so it never leaks across pooled requests (the PgBouncer transaction-mode failure nobody reproduces locally). Includes the InitPlan trick — wrapping the context function in (SELECT ...) — that turns a Seq Scan with a per-row function call into an Index Cond, indexes led by tenant_id, policies that query other tables without infinite recursion, and the back doors that undo everything: views without security_invoker, SECURITY DEFINER functions, materialized views, COPY FROM and pg_dump. It also covers the covert channels in referential integrity (unique indexes that reveal other tenants rows, foreign keys that cross tenants) and the structural defence of composite FKs, isolation tests in pytest, the catalog test that breaks the build when someone adds a table without RLS, eight recurring mistakes, a production checklist and an FAQ. With production-ready SQL, Python and TypeScript.

50 minutes read
0 views

Verificando acceso...

Loading comments...

Related Resources

Guía
PREMIUM

asyncio in Production: Never Block the Event Loop — TaskGroups, Cancellation and Bounded Concurrency

A practical asyncio guide for Python services in production: why blocking the event loop degrades the whole process without raising a single exception, how to catch it by measuring loop lag and with Python 3.14 introspection, structured concurrency with TaskGroup and handling ExceptionGroup via except*, the task the garbage collector makes vanish, timeouts with a deadline budget propagated across services, correct cancellation with cleanup and shield, bounded concurrency with semaphores and backpressured queues, synchronization primitives, and what changes with eager tasks, python -m asyncio pstree and free-threading. With production-ready code and a deployment checklist.

Guía
PREMIUM

Cache-Aside in Production: TTLs, Invalidation, and How to Prevent Cache Stampedes

The complete guide to the cache-aside pattern with Redis: jittered TTLs, correct invalidation, and the three defenses against cache stampedes (distributed lock, single-flight, and XFetch). Expanded with stale-while-revalidate, fail-open and circuit breakers, two-tier caching with RESP3 invalidation, delayed double delete and CDC, hot keys, eviction and memory management, observability with Prometheus, testing, choosing an engine (Redis, Valkey, Memcached), and a complete TypeScript implementation. With production-ready code in Python and TypeScript.

Guía
PREMIUM

Circuit Breakers: How to Prevent Cascading Failures in Distributed Systems

Learn to implement the circuit breaker pattern so a failing dependency never drags down your whole system: the three states (closed, open, half-open), sliding failure windows, limited probes to avoid thundering herds, robust fallbacks, and how to combine it with timeouts, retries, and bulkheads. Includes distributed state in Redis, observability with Prometheus, pytest testing, circuit breaking in Envoy/Istio, a full case study, and production-ready code in Python and TypeScript.