Skip to content
Muhammet Şafak
tr

Just Ask

Ask me anything

Ask me anything about software architecture, careers, PHP, Go and the craft of building software; I answer here, in the open, for everyone. (Page 3/6)

Ask a question

Whatever's on your mind, don't hold back. Questions reach me directly; I answer the good ones and publish them on this page. Your email is never published.

Your email only reaches me and is never published.

Sarp

Why should I use a Sorted Set for a live leaderboard in Redis?

Storing scores as plain strings and sorting in the app is O(N log N) per read over millions of keys. Use a Sorted Set (ZSET): `ZADD` updates in O(log N), `ZREVRANGE 0 99` returns the top 100 already sorted, `ZREVRANK` gives a rank in O(log N). It stays ordered as you write, so reads are near-constant.

#data#redis#performance
Rüzgar

When should I apply CQRS, and how do I sync the read and write models?

Try the cheapest version first: add a read replica and move reporting there — that usually ends the locking. Adopt full CQRS only when query shapes diverge too much for one schema; sync the models event-driven with the outbox pattern, don't dual-write, and accept eventual consistency.

#data#architecture#elasticsearch
Halil

Should I choose NoSQL or PostgreSQL for flexible product attributes?

Don't reach for MongoDB just because attributes vary — that's the NoSQL trap. Keep the relational core (products, prices, orders) in PostgreSQL, put the variable attributes in a GIN-indexed `JSONB` column. Your reporting need alone argues against splitting into Mongo.

#data#architecture#postgresql
Polat

Race condition on balance updates: Pessimistic Lock or Redlock?

For money, keep the invariant in the DB. Use an atomic conditional `UPDATE ... SET balance = balance - 40 WHERE id = ? AND balance >= 40`, or `SELECT ... FOR UPDATE`. Reach for Redlock only for resources that aren't a single DB row; don't trust a distributed lock to protect a balance the DB can enforce.

#data#queue#redis
Eren

Health check design: how do I separate Liveness and Readiness?

Liveness answers 'is the process wedged?' — keep it cheap and dependency-free (don't check the DB here). Readiness answers 'can I serve right now?' — check critical dependencies but cache the result for a few seconds. Liveness fail → restart, readiness fail → stop traffic. Don't let probes DDoS your DB.

#resilience#infrastructure#kubernetes
Furkan

How do I migrate a table to PostgreSQL partitioning with zero downtime?

Use monthly RANGE declarative partitioning on `created_at`. For zero downtime, stand up the new partitioned parent, backfill history in batches while the app keeps writing, then swap names in a single transaction. UNIQUE/PK and FKs must include the partition key.

#database#postgresql#scaling
Sinan

What rules should I follow to prevent database deadlocks?

A deadlock is a lock-ordering cycle. Always acquire locks in the same global order (e.g. ascending PK), keep transactions short and narrow, and use targeted `FOR UPDATE` on the fewest rows. Expect them anyway: the DB aborts a victim, so make the operation idempotent and retry with backoff.

#resilience#database#postgresql
Oğuz

How do I handle panics in a Go HTTP server with recovery middleware?

Put a middleware at the outermost edge of the chain that wraps each request in `defer recover()`, logs the stack + request id, returns a generic 500 and emits a metric. But recover only catches the same goroutine: if you spawn `go func()` inside a handler, that goroutine needs its own recover.

#resilience#go

Search the site

Start typing to search posts, projects and pages.

Esc to close Powered by Pagefind