MonkeyTips

Bite-sized, battle-tested engineering tips — with runnable code, diagrams and challenges.
Most tip content, techniques, and guidance steps are developed with AI assistance.
shape
shape
shape
shape
shape
shape
shape
shape
39 tips 7 topics Updated daily

Database Hard

Cache Stampede Prevention: Locks, XFetch, Stale-While-Revalidate and Laravel Cache::flexible

Why a hot key expiring can melt your database, and four fixes: Cache::lock with double-check, XFetch early expiration, Cache::flexible, and TTL jitter.

Laravel 13 PHP 8.4 Redis 7.4
Diagram Try the challenge
11 min Read tip
Next.js Medium

Secure Next.js Server Actions: zod Validation, useActionState, Error Handling and Auth Checks

A Server Action is a public POST endpoint, not a private function. Authenticate, validate with zod, authorize per resource and return safe errors to useActionState.

Next.js 16 React 19 Zod 4
Diagram Try the challenge
10 min Read tip
DevOps Hard

Rolling vs Blue-Green vs Canary: Deploying Without Breaking the Database

Every deploy runs two versions at once against one database. Compare rolling, blue-green and canary, and learn expand/contract, feature flags and real rollbacks.

Kubernetes 1.33 Laravel 13 PHP 8.4
Diagram Try the challenge
9 min Read tip
JavaScript Medium

Cancelling Work with AbortController: fetch, AbortSignal.timeout, AbortSignal.any and Search

Stale search results and abandoned server work share one fix. Learn AbortController, AbortSignal.timeout and AbortSignal.any, plus cleanup that does not leak.

Node.js 22 TypeScript 5.9 React 19
Diagram Try the challenge
9 min Read tip
Laravel Hard

Transactional Outbox in Laravel: Never Lose an Event Between Your Database and the Broker

Writing to the database and a broker in one request loses or invents events on crashes. Fix the dual-write problem with an outbox table, relay and idempotent consumers.

Laravel 13 PHP 8.4 Mysql 8.4
Diagram Try the challenge
9 min Read tip
Security Medium

CORS Explained: Same-Origin Policy, Preflight, Credentials and Laravel config/cors.php

CORS errors tempt you to reflect any Origin and move on. Learn what the browser checks, when preflight happens, how credentials change the rules, and safe config.

Laravel 13 PHP 8.4 Node.js 22
Diagram Try the challenge
10 min Read tip
PHP Medium

PHP Generators for Memory-Efficient Processing: yield, yield from, send() and LazyCollection

Stream a 2 GB CSV in 2 MB of RAM. How PHP generators work: yield with keys, yield from, send(), Laravel LazyCollection, cursor vs lazyById.

PHP 8.4 Laravel 13
Diagram Try the challenge
11 min Read tip
Database Medium

Optimistic Locking With a Version Column: Fix Lost Updates in Laravel (vs lockForUpdate)

Two users save the same record and one change silently disappears. Fix lost updates with a version column, 409 responses and retries, and know when lockForUpdate fits better.

Laravel 13 PHP 8.4 Mysql 8.4
Diagram Try the challenge
10 min Read tip
DevOps Medium

Health Checks Done Right: Liveness vs Readiness vs Startup Probes

A database query in a liveness probe can turn a 40-second failover into a full outage. Learn what each probe should check, with Kubernetes, Docker and Laravel /up.

Kubernetes 1.33 Laravel 13 PHP 8.4
Diagram Try the challenge
9 min Read tip
JavaScript Medium

Promise.all vs allSettled vs race vs any: Semantics, Error Handling, Timeouts and Concurrency Limits

One flaky service took down a whole dashboard through Promise.all. Learn what each combinator really does, how to add timeouts, and how to cap concurrency.

Node.js 22 TypeScript 5.9
Diagram Try the challenge
10 min Read tip
Laravel Medium

Laravel Pipelines: Turn a 340-Line Checkout Controller into Small, Testable Steps

Use the Laravel Pipeline facade to split checkout flows and query filters into pipe classes you can reorder, reuse and unit test, with the pitfalls to avoid.

Laravel 13 PHP 8.4
Diagram Try the challenge
9 min Read tip
Security Medium

Verifying Webhook Signatures with HMAC: Raw Body, Timing-Safe Compare and Replay Protection

A webhook URL is a public endpoint that changes your data. Verify HMAC signatures on the raw body, compare in constant time and block replays with timestamps.

Laravel 13 PHP 8.4 Node.js 22
Diagram Try the challenge
10 min Read tip
Database Hard

Transaction Isolation Levels: Dirty, Non-Repeatable and Phantom Reads in MySQL and PostgreSQL

Why DB::transaction() did not stop your oversold stock: what each isolation level guarantees in MySQL vs PostgreSQL and how to pick one in Laravel.

Laravel 13 PHP 8.4 Mysql 8.4
Diagram Try the challenge
11 min Read tip
Next.js Medium

Next.js App Router Caching: fetch Cache, revalidate, ISR, revalidateTag and updateTag

Stale prices and leaked user data both come from misunderstood caching. Learn the Next.js layers, ISR, tags, updateTag vs revalidateTag, and when a route goes dynamic.

Next.js 16 React 19 Node.js 22
Diagram Try the challenge
10 min Read tip
PHP Medium

PHP Enums Beyond the Basics: Backed Enums, Methods, tryFrom and Eloquent Casts

One 'canceled' vs 'cancelled' typo can strand orders for days. Use backed enums with methods, interfaces, tryFrom and Eloquent casts to kill magic strings.

PHP 8.4 Laravel 13 Python 3.12
Diagram Try the challenge
11 min Read tip
DevOps Hard

Zero-Downtime Database Migrations with Expand/Contract: Rename Columns Without Breaking Deploys

Renaming a column mid-deploy breaks old servers and queue workers. Use expand/contract, batched backfills and the right deploy order to change schemas safely.

Laravel 13 PHP 8.4 Mysql 8.4
Diagram Try the challenge
12 min Read tip
Database Medium

Offset vs Cursor Pagination: Why Page 4,000 Is Slow and How Keyset Queries Fix It

OFFSET makes deep pages slow and shuffles rows when data changes. Learn keyset queries, composite cursors, Laravel cursorPaginate and cursor-based API design.

Laravel 13 PHP 8.4 Mysql 8.4
Diagram Try the challenge
11 min Read tip
Security Medium

Password Hashing Done Right: bcrypt vs Argon2id, Cost Tuning and Rehash on Login

MD5 and SHA-256 crack in hours once a dump leaks. Pick bcrypt or Argon2id, tune the cost on real hardware and upgrade old hashes on login in PHP and Laravel.

PHP 8.4 Laravel 13 Python 3.13
Diagram Try the challenge
11 min Read tip
JavaScript Medium

JavaScript Event Loop: Microtasks vs Macrotasks, Predicting Output Order, and Starving the Loop

Sync code, then all microtasks, then one macrotask. Use that rule to predict Promise vs setTimeout order and to stop async loops from freezing Node.

Node.js 22 Ecmascript 2024
Diagram Try the challenge
11 min Read tip
Laravel Medium

Laravel Job Batching vs Chains: Progress, Failures, allowFailures and then/catch/finally

Bus::chain runs jobs in order and stops at the first failure; Bus::batch runs them in parallel with progress and callbacks. Learn exactly when then, catch and finally fire.

Laravel 13 PHP 8.4
Diagram Try the challenge
10 min Read tip
DevOps Medium

Circuit Breaker Pattern: Stop Hammering a Service That Is Already Down

Retries alone can bury a struggling dependency. Learn how a circuit breaker fails fast, lets the service recover and probes it safely, with PHP, Python and Laravel code.

PHP 8.4 Python 3.12
Diagram Try the challenge
6 min Read tip
DevOps Medium

Exponential Backoff with Jitter: Retrying Failed Requests the Right Way

Why naive exponential backoff causes retry storms, and how adding random jitter smooths out the load, with a full-jitter retry implementation in PHP and Python.

PHP 8.4 Python 3.12
Diagram Try the challenge
4 min Read tip
DevOps Hard

Consistent Hashing: Distributing Load Without a Full Reshuffle

How consistent hashing distributes keys across nodes so adding or removing a node only reshuffles a small fraction of the keyspace, with a virtual-node implementation in PHP and Python.

PHP 8.4 Python 3.12
Diagram Try the challenge
3 min Read tip
PHP Medium

LRU Cache: Design an O(1) Cache with a Doubly Linked List and Hash Map

How to design an LRU cache that supports get and put in O(1) time using a hash map paired with a doubly linked list, with a working PHP implementation and a hands-on coding challenge.

PHP 8.4
Diagram Try the challenge
4 min Read tip
Laravel Medium

Idempotency Keys: Preventing Duplicate Payments in Distributed Systems

Why idempotency keys matter in payment APIs, how to implement them safely with a database-backed store, and common pitfalls like race conditions and key collisions.

PHP 8.4
Diagram
4 min Read tip
Database Hard

Database Deadlocks: Detection, Diagnosis, and Prevention

How relational databases detect deadlocks with wait-for graphs, why they happen, and concrete techniques to prevent them in high-concurrency systems.

Postgresql 13+
Diagram
5 min Read tip
Database Hard

Distributed Locking with Redis: Understanding the Redlock Algorithm

A deep dive into the Redlock algorithm for safe distributed locking across multiple Redis nodes, including failure modes, clock drift, and the fencing token fix.

Redis 7.x
Diagram
6 min Read tip
DevOps Medium

Git Interactive Rebase: Clean Up Your Commit History Before a PR

Learn how to use git rebase -i to squash, reorder, and edit commits so your pull requests tell a clean, reviewable story.

Git 2.40+
Diagram
4 min Read tip
Database Medium

Redis Caching Strategies: Cache-Aside vs Write-Through

Compare cache-aside and write-through caching with Redis, including consistency trade-offs, TTL strategy, and when to use each pattern.

Redis 7.x
Diagram
4 min Read tip
JavaScript Medium

TypeScript Utility Types: Pick, Omit, and Partial Explained

Stop duplicating interfaces for every slightly-different shape. Pick, Omit, and Partial let you derive new types from one source of truth — here's when to reach for each.

TypeScript 5.x
Diagram
3 min Read tip
Security Medium

Rate Limiting APIs: Token Bucket vs Sliding Window

Fixed windows let clients burst 2x at the boundary. See how token bucket and sliding window rate limiting actually work, with Redis-backed implementations and the pitfalls that break them in production.

Redis 6.x+ Node 18.x+
Diagram
2 min Read tip
Next.js Medium

Next.js App Router: Server Components vs Client Components

Server Components run only on the server; Client Components hydrate in the browser. See how Next.js App Router renders both, and when to actually reach for 'use client'.

Next 14.x - 15.x React 18.x - 19.x
Diagram
3 min Read tip
JavaScript Medium

Debounce vs Throttle in JavaScript: Control How Often Code Runs

Scroll, resize, and keystroke events fire dozens of times a second. Learn how debounce and throttle rate-limit them — and which one to reach for.

JavaScript ES6+
Diagram
2 min Read tip
Database Medium

Database Indexes: Turn a Full Scan Into an Instant Lookup

See why a query without an index scans every row, how an index turns it into a fast lookup, and how to read EXPLAIN to tell the difference.

SQL ANSI / MySQL 8+
Diagram
2 min Read tip
PHP Easy

Preventing SQL Injection in PHP

Learn essential techniques to protect your PHP applications from SQL injection attacks.

PHP 8.0+
Diagram
2 min Read tip
DevOps Medium

Docker Multi-Stage Builds for Smaller Images

Reduce your Docker image size dramatically using multi-stage builds.

Docker 20.10+
Diagram
2 min Read tip
PHP Medium

PHP 8.4 Property Hooks Explained

Discover the new property hooks feature in PHP 8.4 that provides a cleaner way to add logic to property access.

PHP 8.4
1 min Read tip
Laravel Medium

Laravel Query Optimization with Eager Loading

Learn how to optimize database queries in Laravel by using eager loading to prevent N+1 query problems.

Laravel 11.x PHP 8.2+
Diagram
2 min Read tip
JavaScript Easy

JavaScript Async/Await Best Practices

Master async/await in JavaScript with these best practices and common pitfalls to avoid.

JavaScript ES2017+
Diagram
1 min Read tip

No tips found

Try a different topic, level or search term.