performance

Image caching with NSCache and async loading

Loading images from URLs requires caching to avoid redundant network calls and improve performance. I create an image cache using NSCache which automatically evicts objects under memory pressure. The cache stores UIImage or Data keyed by URL. For asyn

Table partitioning for large datasets

Partitioning splits large tables into smaller physical pieces. Range partitioning divides by value ranges—dates, IDs. List partitioning groups by specific values—regions, categories. Hash partitioning distributes evenly across partitions. I use partit

Gzip compression middleware with correct Vary header

Compressing responses is an easy bandwidth win for JSON APIs, but only when it's done carefully. I check Accept-Encoding for gzip, set Vary: Accept-Encoding so caches behave correctly, and stream output through gzip.Writer so we don't buffer full resp

Optimistic UI updates with Turbo Streams

Waiting for server confirmation makes interfaces feel sluggish. Optimistic updates immediately show the expected result, then reconcile with the server response. When a user likes a post, I increment the count immediately via Stimulus, submit the requ

Fast “Exists” Checks with select(1) and LIMIT

Avoid loading whole records when you only need to know if something exists. exists? is good; for complex joins, a scoped select(1).limit(1) can be clearer and keeps the DB workload low.

Benchmarking hot paths (allocs and throughput)

When latency matters, I benchmark the smallest interesting unit and watch allocations. In Go, a surprising number of regressions come from accidental heap churn: converting []byte to string, building lots of temporary maps, or using fmt.Sprintf in loo

N+1 avoidance with DataLoader (GraphQL)

GraphQL makes it very easy to accidentally create N+1 query explosions. DataLoader batches requests for the same resource during a single tick and gives you per-request caching. The trick is scoping: loaders must be per-request, not global singletons,

Bulk Upsert with insert_all + Unique Index

I stopped doing row-by-row imports once they started hammering the DB. In Migration (unique index), I added a real uniqueness guarantee on provider + uid, because bulk writes only stay correct if the database can enforce constraints. Then, in Bulk ups

Query performance monitoring and profiling

Performance monitoring identifies slow queries and bottlenecks. I use EXPLAIN ANALYZE to profile query execution. pgstatstatements tracks query statistics over time. Slow query logs capture problematic queries. Query execution time, I/O, and buffer us

Pagination with cursor-based approach

Traditional offset-based pagination becomes unreliable and slow for large datasets when records are frequently inserted or deleted—users can miss items or see duplicates across pages. Cursor-based pagination solves this by using an opaque token that e

Database indexes for query optimization

Proper indexing is the difference between millisecond and multi-second query response times. I add indexes to foreign keys automatically since Rails doesn't do this by default, and I create composite indexes for common query patterns that filter on mu

Use `touch_all` for Efficient “Bump Updated At”

When you need to invalidate caches by changing timestamps, use touch_all to avoid per-record callbacks. It’s fast, explicit, and doesn’t run unintended side effects.