# Just Ask: Software Questions & Answers

> Ask me anything about software architecture, careers, PHP, Go and the craft of building software; I answer here, in the open, for everyone.

- Answered questions: 71
- Source: https://www.muhammetsafak.com.tr/en/just-ask/
- Language: en-US
- Author: Muhammet Şafak

---
## Answered questions

### Should I run several dependent operations with errgroup so the first error cancels the rest?

- Move to `errgroup.WithContext` with a request-level timeout on top and thread ctx into every HTTP and DB call; an ignored ctx means no cancellation at all.
- Asked by: Onur
- Answered: 2026-09-04
- Tags: #Go, #Concurrency
- https://www.muhammetsafak.com.tr/en/just-ask/should-i-run-several-dependent-operations-with-errgroup-so-the-first/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/should-i-run-several-dependent-operations-with-errgroup-so-the-first.md

### Should I use chunkById instead of chunk when the same job also updates the rows it iterates?

- Use `chunkById()` when there is real per-row work and never touch the cursor column; if you only update a column, switch to one set-based `UPDATE`.
- Asked by: Naz
- Answered: 2026-09-01
- Tags: #Laravel, #Eloquent, #Performance
- https://www.muhammetsafak.com.tr/en/just-ask/should-i-use-chunkbyid-instead-of-chunk-when-the-same-job/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/should-i-use-chunkbyid-instead-of-chunk-when-the-same-job.md

### How do I cleanly implement "withX" copy methods on readonly value objects?

- A readonly withX returns a new instance: `new self` with named arguments is portable, and `clone($this, [...])` fits PHP 8.5 when validation is simple.
- Asked by: Kaan
- Answered: 2026-08-28
- Tags: #PHP, #OOP
- https://www.muhammetsafak.com.tr/en/just-ask/how-do-i-cleanly-implement-withx-copy-methods-on-readonly-value/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/how-do-i-cleanly-implement-withx-copy-methods-on-readonly-value.md

### How does the nature of the work change on the jump from senior to staff?

- Take an ownerless org-level problem, lay the solution out in a written tech strategy, and show impact through the teams you accelerate, not your commits.
- Asked by: Derya
- Answered: 2026-08-25
- Tags: #Career, #Leadership
- https://www.muhammetsafak.com.tr/en/just-ask/how-does-the-nature-of-the-work-change-on-the-jump/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/how-does-the-nature-of-the-work-change-on-the-jump.md

### How should I carry a correlation ID from the HTTP request all the way into queued jobs?

- Generate the ID as a W3C `traceparent`, carry it in an SQS message attribute rather than the body, and inject it with the OTel propagator on both sides.
- Asked by: Cem
- Answered: 2026-08-21
- Tags: #Observability, #Logging, #Queue
- https://www.muhammetsafak.com.tr/en/just-ask/how-should-i-carry-a-correlation-id-from-the-http-request/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/how-should-i-carry-a-correlation-id-from-the-http-request.md

### My non-root container can't write to the mounted storage directory—how do I fix the permissions?

- Pin the user with a build-time `ARG UID`, use `COPY --chown`, and for named volumes chown only `storage` and `bootstrap/cache` in the entrypoint.
- Asked by: Barış
- Answered: 2026-08-18
- Tags: #Docker, #Security, #Laravel
- https://www.muhammetsafak.com.tr/en/just-ask/my-non-root-container-cant-write-to-the-mounted-storage-directory/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/my-non-root-container-cant-write-to-the-mounted-storage-directory.md

### Should I author the OpenAPI spec first or generate it from my code?

- Go contract-first with `openapi.yaml` as the single source of truth; what ends drift isn't the direction you pick but a green contract test running in CI.
- Asked by: Ece
- Answered: 2026-08-14
- Tags: #API, #API Design
- https://www.muhammetsafak.com.tr/en/just-ask/should-i-author-the-openapi-spec-first-or-generate-it-from/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/should-i-author-the-openapi-spec-first-or-generate-it-from.md

### Should I use a partial index on a queue table where I only ever scan 'pending' rows?

- Build the partial index on `WHERE status='pending'`, include the `ORDER BY` column, pair it with `FOR UPDATE SKIP LOCKED`, and pass 'pending' literally.
- Asked by: Yiğit
- Answered: 2026-08-11
- Tags: #PostgreSQL, #Database, #Performance
- https://www.muhammetsafak.com.tr/en/just-ask/should-i-use-a-partial-index-on-a-queue-table-where/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/should-i-use-a-partial-index-on-a-queue-table-where.md

### How do I propagate context cancellation correctly through nested service calls?

- Cancellation propagates only if you pass `r.Context()` into every downstream call, leave no `context.Background()` in the chain, and use `WithoutCancel`.
- Asked by: Tolga
- Answered: 2026-08-07
- Tags: #Go, #Concurrency
- https://www.muhammetsafak.com.tr/en/just-ask/how-do-i-propagate-context-cancellation-correctly-through-nested-service-calls/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/how-do-i-propagate-context-cancellation-correctly-through-nested-service-calls.md

### Should I bind a Money value object to Eloquent with a custom cast or with accessors/mutators?

- Integer cents in the DB, an immutable `Money` on the model: put the mapping in one `CastsAttributes` class and keep currency as a second column there.
- Asked by: Sıla
- Answered: 2026-08-04
- Tags: #Laravel, #Eloquent, #PHP
- https://www.muhammetsafak.com.tr/en/just-ask/should-i-bind-a-money-value-object-to-eloquent-with-a/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/should-i-bind-a-money-value-object-to-eloquent-with-a.md

### Should I use PHPStan generics for type-safe collections or hand-write a class per type?

- Default to `list<Order>` docblocks with strict PHPStan in CI; add one generic `Collection<T>` for behavior, a concrete class only at a trust boundary.
- Asked by: Ozan
- Answered: 2026-07-31
- Tags: #PHP, #Static Analysis
- https://www.muhammetsafak.com.tr/en/just-ask/should-i-use-phpstan-generics-for-type-safe-collections-or-hand/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/should-i-use-phpstan-generics-for-type-safe-collections-or-hand.md

### How do I demonstrate the broader impact expected when moving from mid-level to senior?

- Turn the promotion into a concrete move: pick one fuzzy problem nobody owns and carry it end to end for a quarter, from its definition to its rollout.
- Asked by: Deniz
- Answered: 2026-07-28
- Tags: #Career
- https://www.muhammetsafak.com.tr/en/just-ask/how-do-i-demonstrate-the-broader-impact-expected-when-moving-from/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/how-do-i-demonstrate-the-broader-impact-expected-when-moving-from.md

### How do I set a clear rule for when to log at WARN versus ERROR?

- Log at ERROR when the line would wake someone at 3am and at WARN when it would not, log a failure once at its boundary, and alert on the ERROR rate.
- Asked by: Can
- Answered: 2026-07-24
- Tags: #Observability, #Logging
- https://www.muhammetsafak.com.tr/en/just-ask/how-do-i-set-a-clear-rule-for-when-to-log/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/how-do-i-set-a-clear-rule-for-when-to-log.md

### Should I define the healthcheck in the Dockerfile or leave it to Kubernetes probes?

- Define readiness, liveness and startup as Kubernetes probes; keep HEALTHCHECK only if the image also runs under Compose, pointing both at one endpoint.
- Asked by: Elif
- Answered: 2026-07-21
- Tags: #Docker, #Kubernetes, #Reliability
- https://www.muhammetsafak.com.tr/en/just-ask/should-i-define-the-healthcheck-in-the-dockerfile-or-leave-it/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/should-i-define-the-healthcheck-in-the-dockerfile-or-leave-it.md

### How should I run the sunset process when deprecating an endpoint in my public API?

- Instrument usage per partner, publish a dated sunset with Sunset and Deprecation headers on every response, run brownouts, and cut when usage nears zero.
- Asked by: Burak
- Answered: 2026-07-17
- Tags: #API, #API Design
- https://www.muhammetsafak.com.tr/en/just-ask/how-should-i-run-the-sunset-process-when-deprecating-an-endpoint/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/how-should-i-run-the-sunset-process-when-deprecating-an-endpoint.md

### Why does a query use an Index Scan in staging but a Seq Scan in production, and how do I diagnose it with EXPLAIN?

- Run EXPLAIN (ANALYZE, BUFFERS) in production, then ANALYZE the table and check n_dead_tup; tune autovacuum per-table for sessions and add a partial index.
- Asked by: Zeynep
- Answered: 2026-07-14
- Tags: #PostgreSQL, #Performance
- https://www.muhammetsafak.com.tr/en/just-ask/why-does-a-query-use-an-index-scan-in-staging-but/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/why-does-a-query-use-an-index-scan-in-staging-but.md

### How do I detect and prevent goroutine leaks in a long-running Go service?

- Export NumGoroutine() as a metric, take a pprof goroutine dump at peak, make the spawn site behind the parked stacks honor ctx.Done(), then add goleak.
- Asked by: Kerem
- Answered: 2026-07-10
- Tags: #Go, #Concurrency
- https://www.muhammetsafak.com.tr/en/just-ask/how-do-i-detect-and-prevent-goroutine-leaks-in-a-long/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/how-do-i-detect-and-prevent-goroutine-leaks-in-a-long.md

### Should I enable Model::preventLazyLoading only locally or in production too?

- Run it fully strict and throwing in local and CI; in production keep it on but wire handleLazyLoadingViolationUsing to log without failing the request.
- Asked by: Ayşe
- Answered: 2026-07-07
- Tags: #Laravel, #Eloquent, #Performance
- https://www.muhammetsafak.com.tr/en/just-ask/should-i-enable-model-preventlazyloading-only-locally-or-in-production-too/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/should-i-enable-model-preventlazyloading-only-locally-or-in-production-too.md

### What do I gain and lose by moving my status class constants to backed enums?

- Add a backed enum on the same integer values, use tryFrom() at the boundaries, and keep the old constants as deprecated aliases while you move call sites.
- Asked by: Mert
- Answered: 2026-07-03
- Tags: #PHP, #Refactoring
- https://www.muhammetsafak.com.tr/en/just-ask/what-do-i-gain-and-lose-by-moving-my-status-class/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/what-do-i-gain-and-lose-by-moving-my-status-class.md

### How do I design a self-healing deploy that auto-rolls back when the error rate spikes?

- Hold the new version at a canary weight and check 5xx and latency against a threshold; on breach, roll back to the last stable release and alert the team.
- Asked by: Emir
- Answered: 2026-06-13
- Tags: #CI/CD, #Resilience, #Observability
- https://www.muhammetsafak.com.tr/en/just-ask/automated-rollback-on-error-spikes-self-healing-deploys/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/automated-rollback-on-error-spikes-self-healing-deploys.md

### Should I put my API server behind a Cloudflare Tunnel and close port 443 to the internet?

- The tunnel is sound but makes Cloudflare your only way in; stay on the current Caddy setup, lock the origin to Cloudflare's IP ranges and add origin pulls.
- Asked by: Gazi
- Answered: 2026-06-13
- Tags: #Infrastructure, #Cloudflare, #Laravel
- https://www.muhammetsafak.com.tr/en/just-ask/should-i-put-my-api-behind-a-cloudflare-tunnel/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/should-i-put-my-api-behind-a-cloudflare-tunnel.md

### Canary or Blue-Green deployment for a fintech API?

- Make Canary the default for routine releases and save Blue-Green for big cutovers needing an instant flip, since both demand expand/contract migrations.
- Asked by: Bora
- Answered: 2026-06-12
- Tags: #CI/CD, #Resilience
- https://www.muhammetsafak.com.tr/en/just-ask/canary-vs-blue-green-deployment-for-a-fintech-api/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/canary-vs-blue-green-deployment-for-a-fintech-api.md

### Why is keeping the key in .env risky when encrypting sensitive financial data — what do KMS/Vault give you?

- Take the key out of .env, keep it in KMS or Vault and use envelope encryption; for national IDs and card data, prefer tokenization wherever you can.
- Asked by: Çağrı
- Answered: 2026-06-12
- Tags: #Database, #Security, #Infrastructure
- https://www.muhammetsafak.com.tr/en/just-ask/encrypting-sensitive-financial-data-at-rest-and-key-management/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/encrypting-sensitive-financial-data-at-rest-and-key-management.md

### How do I position feature flags when moving from Gitflow to Trunk-Based?

- Drop the long-lived branches, merge small changes to main continuously, keep unfinished work behind a flag that's off in prod, and delete flags once done.
- Asked by: Tarık
- Answered: 2026-06-12
- Tags: #CI/CD, #Git, #Architecture
- https://www.muhammetsafak.com.tr/en/just-ask/gitflow-vs-trunk-based-development-and-feature-flags/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/gitflow-vs-trunk-based-development-and-feature-flags.md

### How do I isolate self-hosted CI/CD runners and build an ephemeral, clean-after-each-run environment?

- Move the runner to a register-run-once-destroy model and run jobs unprivileged; never hand over the Docker socket, and never run fork PRs on it.
- Asked by: Cüneyt
- Answered: 2026-06-12
- Tags: #CI/CD, #Security, #Docker
- https://www.muhammetsafak.com.tr/en/just-ask/isolating-and-securing-self-hosted-ci-cd-runners/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/isolating-and-securing-self-hosted-ci-cd-runners.md

### How do I distribute a Go CLI to multiple platforms with GoReleaser and Homebrew?

- Let one tag-triggered workflow cross-compile and publish the GitHub Release while the homebrew_casks: block updates the tap; the tap needs its own PAT.
- Asked by: Devrim
- Answered: 2026-06-12
- Tags: #CI/CD, #Go
- https://www.muhammetsafak.com.tr/en/just-ask/multi-platform-go-cli-distribution-with-goreleaser-and-homebrew/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/multi-platform-go-cli-distribution-with-goreleaser-and-homebrew.md

### How do I rewind to seconds before a disaster with WAL archiving and PITR?

- Take a periodic base backup, archive WAL to S3 continuously, replay to a recovery_target_time seconds before the bad statement, and rehearse the restore.
- Asked by: Yusuf
- Answered: 2026-06-12
- Tags: #Database, #PostgreSQL, #Resilience
- https://www.muhammetsafak.com.tr/en/just-ask/point-in-time-recovery-with-wal-archiving/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/point-in-time-recovery-with-wal-archiving.md

### How do I run database migrations safely in CI/CD?

- Add the column nullable, move the backfill to a separate throttled step, run migrations in their own stage, and drop the old column in a later release.
- Asked by: Melih
- Answered: 2026-06-12
- Tags: #CI/CD, #Database, #Laravel
- https://www.muhammetsafak.com.tr/en/just-ask/running-database-migrations-safely-in-ci-cd/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/running-database-migrations-safely-in-ci-cd.md

### How do I set up secretless AWS access in CI/CD with OIDC and IAM roles?

- Delete the long-lived AWS keys from GitHub Secrets and assume a repo/branch-scoped IAM role over OIDC; pull non-cloud secrets from a manager at runtime.
- Asked by: Doruk
- Answered: 2026-06-12
- Tags: #CI/CD, #Security, #Infrastructure
- https://www.muhammetsafak.com.tr/en/just-ask/secretless-ci-cd-with-aws-iam-roles-and-oidc/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/secretless-ci-cd-with-aws-iam-roles-and-oidc.md

### How do I shrink Docker images with multi-stage builds and distroless?

- Leave the build tools in the builder stage: make the final stage distroless/static or scratch for Go and fpm-alpine for PHP, and run as non-root.
- Asked by: Korhan
- Answered: 2026-06-12
- Tags: #CI/CD, #Docker, #Infrastructure
- https://www.muhammetsafak.com.tr/en/just-ask/shrinking-docker-images-with-multi-stage-builds-and-distroless/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/shrinking-docker-images-with-multi-stage-builds-and-distroless.md

### How do I safely manage Terraform state with S3 + DynamoDB locking?

- Move state to a versioned, encrypted S3 backend and add a DynamoDB lock table (deprecated but working), keep state per environment, and apply only from CI.
- Asked by: Nadir
- Answered: 2026-06-12
- Tags: #CI/CD, #Infrastructure
- https://www.muhammetsafak.com.tr/en/just-ask/terraform-remote-state-and-locking-with-s3-and-dynamodb/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/terraform-remote-state-and-locking-with-s3-and-dynamodb.md

### How do I stop OPcache from causing 500s during a zero-downtime DeployerPHP deploy?

- After flipping the symlink, gracefully reload PHP-FPM rather than restarting it; on Octane, octane:reload is mandatory and opcache_reset is optional.
- Asked by: Şükrü
- Answered: 2026-06-12
- Tags: #CI/CD, #Laravel
- https://www.muhammetsafak.com.tr/en/just-ask/zero-downtime-deployment-with-deployerphp-and-opcache/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/zero-downtime-deployment-with-deployerphp-and-opcache.md

### Time-series data: TimescaleDB or InfluxDB?

- 100M rows a day breaks a plain table, so chunk it by time with hypertables, materialize the averages as continuous aggregates, and compress the old chunks.
- Asked by: Uğur
- Answered: 2026-06-11
- Tags: #Database, #PostgreSQL, #Scaling
- https://www.muhammetsafak.com.tr/en/just-ask/time-series-data-timescaledb-vs-naive-solutions/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/time-series-data-timescaledb-vs-naive-solutions.md

### How do I coordinate a zero-loss schema migration with dual-writing on a live table?

- Instead of a blocking `ALTER TABLE` on 20M rows run expand/contract: add nullable columns, dual-write, backfill in throttled batches, then drop the old.
- Asked by: Taylan
- Answered: 2026-06-11
- Tags: #Database, #PostgreSQL, #CI/CD
- https://www.muhammetsafak.com.tr/en/just-ask/zero-loss-schema-migration-with-dual-writing-on-a-live-table/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/zero-loss-schema-migration-with-dual-writing-on-a-live-table.md

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

- Use a Sorted Set instead of plain string keys sorted in the app, since `ZADD` updates in O(log N) and `ZREVRANGE 0 99` returns the top 100 already ordered.
- Asked by: Sarp
- Answered: 2026-06-10
- Tags: #Database, #Redis, #Performance
- https://www.muhammetsafak.com.tr/en/just-ask/redis-data-types-using-sorted-sets-for-a-leaderboard/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/redis-data-types-using-sorted-sets-for-a-leaderboard.md

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

- Move reporting to a read replica and adopt CQRS only when query shapes outgrow one schema, feeding the read model from outbox events, not dual-writes.
- Asked by: Rüzgar
- Answered: 2026-06-09
- Tags: #Database, #Architecture, #ElasticSearch
- https://www.muhammetsafak.com.tr/en/just-ask/when-to-apply-cqrs-and-syncing-read-and-write-models/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/when-to-apply-cqrs-and-syncing-read-and-write-models.md

### Should I choose NoSQL or PostgreSQL for flexible product attributes?

- Keep products, prices and orders in PostgreSQL and put the variable attributes in one GIN-indexed `JSONB` column; reporting alone rules out splitting.
- Asked by: Halil
- Answered: 2026-06-08
- Tags: #Database, #Architecture, #PostgreSQL
- https://www.muhammetsafak.com.tr/en/just-ask/nosql-vs-relational-for-flexible-product-attributes/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/nosql-vs-relational-for-flexible-product-attributes.md

### Race condition on balance updates: Pessimistic Lock or Redlock?

- Keep the invariant in the DB with an atomic `UPDATE ... WHERE balance >= 40` or a `SELECT ... FOR UPDATE`, and save Redlock for non-DB resources.
- Asked by: Polat
- Answered: 2026-06-08
- Tags: #Database, #Queue, #Redis
- https://www.muhammetsafak.com.tr/en/just-ask/preventing-race-conditions-on-balance-updates-pessimistic-vs-redlock/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/preventing-race-conditions-on-balance-updates-pessimistic-vs-redlock.md

### How do I handle poison-pill messages and a Dead Letter Queue in the queue?

- Put `tries` and a `backoff` on the job so it lands in `failed_jobs` at the cap, alert from a `JobFailed` listener and replay it with `queue:retry`.
- Asked by: Gökhan
- Answered: 2026-06-07
- Tags: #Resilience, #Queue, #Laravel
- https://www.muhammetsafak.com.tr/en/just-ask/poison-pill-messages-and-dead-letter-queues-in-laravel/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/poison-pill-messages-and-dead-letter-queues-in-laravel.md

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

- Keep liveness dependency-free and check dependencies in readiness with a cached probe, since liveness restarts the pod while readiness only sheds traffic.
- Asked by: Eren
- Answered: 2026-06-06
- Tags: #Resilience, #Infrastructure, #Kubernetes
- https://www.muhammetsafak.com.tr/en/just-ask/health-check-design-liveness-vs-readiness/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/health-check-design-liveness-vs-readiness.md

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

- Stand up monthly RANGE declarative partitioning on `created_at`, backfill history in batches while the app writes, then swap names in a single transaction.
- Asked by: Furkan
- Answered: 2026-06-06
- Tags: #Database, #PostgreSQL, #Scaling
- https://www.muhammetsafak.com.tr/en/just-ask/zero-downtime-migration-to-postgresql-declarative-partitioning/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/zero-downtime-migration-to-postgresql-declarative-partitioning.md

### What rules should I follow to prevent database deadlocks?

- Acquire locks in one global order such as ascending PK, keep transactions short, target `FOR UPDATE` at the fewest rows, and retry the rest with backoff.
- Asked by: Sinan
- Answered: 2026-06-05
- Tags: #Resilience, #Database, #PostgreSQL
- https://www.muhammetsafak.com.tr/en/just-ask/detecting-and-preventing-database-deadlocks/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/detecting-and-preventing-database-deadlocks.md

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

- Wrap requests in a `defer recover()` middleware at the outermost layer, log the stack with the request id, return a generic 500 and emit a metric.
- Asked by: Oğuz
- Answered: 2026-06-04
- Tags: #Resilience, #Go
- https://www.muhammetsafak.com.tr/en/just-ask/panic-recovery-middleware-in-go-http-servers/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/panic-recovery-middleware-in-go-http-servers.md

### Disaster recovery: how do I design an active-passive scenario around RTO and RPO?

- RPO 5min buys continuous cross-region replication and PITR, RTO 30min an IaC-provisioned warm standby behind Route 53 failover, rehearsed on a game-day.
- Asked by: Levent
- Answered: 2026-06-03
- Tags: #Resilience, #Infrastructure, #Database
- https://www.muhammetsafak.com.tr/en/just-ask/disaster-recovery-strategy-setting-rto-and-rpo/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/disaster-recovery-strategy-setting-rto-and-rpo.md

### How do I prevent log storms and disk-full outages?

- Collapse repeated errors into one counted line, back off retries, cap logrotate by size and count, and give `/var/log` a volume off the root disk.
- Asked by: Serkan
- Answered: 2026-06-02
- Tags: #Resilience, #Observability, #Infrastructure
- https://www.muhammetsafak.com.tr/en/just-ask/preventing-log-storms-and-disk-full-outages/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/preventing-log-storms-and-disk-full-outages.md

### How do I build smart rate limiting against distributed brute force and DDoS?

- Per-IP limits lose to rotating proxies, so key the Redis sliding-window on account + IP + ASN, add account lockout and leave volumetric floods to the edge.
- Asked by: Murat
- Answered: 2026-06-01
- Tags: #Resilience, #Security, #Redis
- https://www.muhammetsafak.com.tr/en/just-ask/smart-rate-limiting-against-distributed-brute-force-and-ddos/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/smart-rate-limiting-against-distributed-brute-force-and-ddos.md

### Graceful degradation: how do I isolate non-critical services under load?

- Split the critical path (browse, cart, checkout) from the nice-to-haves, put those behind feature flags with short timeouts, and rehearse the kill-switch.
- Asked by: Hakan
- Answered: 2026-05-31
- Tags: #Resilience, #Architecture, #Scaling
- https://www.muhammetsafak.com.tr/en/just-ask/graceful-degradation-isolating-non-critical-services-under-load/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/graceful-degradation-isolating-non-critical-services-under-load.md

### How do I design eventual consistency with the Saga Pattern in a distributed system?

- Split the transaction into local steps with compensating actions, driven by one orchestrator over a queue, each idempotent and published through an outbox.
- Asked by: İpek
- Answered: 2026-05-30
- Tags: #Resilience, #Microservices, #Queue
- https://www.muhammetsafak.com.tr/en/just-ask/orchestrated-saga-for-eventual-consistency-across-services/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/orchestrated-saga-for-eventual-consistency-across-services.md

### How do I prevent PostgreSQL split-brain with quorum and consensus?

- Don't hand-roll failover: put promotion behind a Patroni + etcd quorum, and let a primary cut off from the majority demote itself by fencing.
- Asked by: Volkan
- Answered: 2026-05-29
- Tags: #Resilience, #PostgreSQL, #Database
- https://www.muhammetsafak.com.tr/en/just-ask/avoiding-postgresql-split-brain-with-quorum-and-consensus/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/avoiding-postgresql-split-brain-with-quorum-and-consensus.md

### How do I set up a Circuit Breaker for a flaky third-party API dependency?

- A breaker alone won't hold: pull `connect_timeout` and `timeout` down to 800ms-2s, isolate the dependency behind a bulkhead, and define a cached fallback.
- Asked by: Tunç
- Answered: 2026-05-28
- Tags: #Resilience, #Architecture, #Laravel
- https://www.muhammetsafak.com.tr/en/just-ask/circuit-breaker-for-flaky-third-party-apis/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/circuit-breaker-for-flaky-third-party-apis.md

### How do I set up CDN asset versioning: hashing and a cache strategy on deploy?

- Drop query-string busting: cache content-hashed filenames as `immutable`, keep the HTML short-lived, and upload the assets before you cut over.
- Asked by: Aslı
- Answered: 2026-05-27
- Tags: #Performance, #CI/CD, #Infrastructure
- https://www.muhammetsafak.com.tr/en/just-ask/cdn-asset-versioning-and-cache-strategy-on-deploy/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/cdn-asset-versioning-and-cache-strategy-on-deploy.md

### How do I make search-as-you-type fast with edge n-grams in Elasticsearch?

- Drop wildcard for autocomplete; build the prefixes at index time with edge_ngram and keep a standard search analyzer so a keystroke is a plain term lookup.
- Asked by: Efe
- Answered: 2026-05-26
- Tags: #Performance, #ElasticSearch, #Database
- https://www.muhammetsafak.com.tr/en/just-ask/search-as-you-type-performance-with-edge-ngram-in-elasticsearch/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/search-as-you-type-performance-with-edge-ngram-in-elasticsearch.md

### How do I stream 2-5 GB file downloads without blowing up PHP's memory?

- Serve 2-5 GB files outside PHP via a presigned URL or X-Accel-Redirect; if it must go through PHP, chunk it with readStream and turn off buffering.
- Asked by: Barış
- Answered: 2026-05-25
- Tags: #Performance, #Laravel, #Infrastructure
- https://www.muhammetsafak.com.tr/en/just-ask/streaming-multi-gigabyte-file-downloads-without-exhausting-php-memory/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/streaming-multi-gigabyte-file-downloads-without-exhausting-php-memory.md

### How do HTTP/2 and HTTP/3 (QUIC) improve API performance?

- Turn on HTTP/2 today, since multiplexing collapses 4-5 requests per screen onto one connection; add HTTP/3 for a mobile audience and drop domain sharding.
- Asked by: Kerem
- Answered: 2026-05-24
- Tags: #Performance, #Infrastructure, #Networking
- https://www.muhammetsafak.com.tr/en/just-ask/how-http-2-and-http-3-improve-api-performance/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/how-http-2-and-http-3-improve-api-performance.md

### Which PgBouncer pooling mode should I pick — Session, Transaction, or Statement?

- Pick Transaction mode for a web fleet; the price is protocol-level prepared statements, so disable them in the app or turn on PgBouncer 1.21+ support.
- Asked by: Pelin
- Answered: 2026-05-23
- Tags: #Performance, #PostgreSQL, #Database
- https://www.muhammetsafak.com.tr/en/just-ask/pgbouncer-pooling-modes-and-prepared-statements/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/pgbouncer-pooling-modes-and-prepared-statements.md

### Should I start a new project with microservices?

- For most greenfield products, start with a modular monolith and enforce boundaries in code, promoting a module to a service only when it must scale alone.
- Asked by: Emre
- Answered: 2026-05-22
- Tags: #Architecture, #Microservices
- https://www.muhammetsafak.com.tr/en/just-ask/should-i-start-a-new-project-with-microservices/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/should-i-start-a-new-project-with-microservices.md

### How do I do graceful shutdown on SIGTERM during autoscaling scale-in?

- On SIGTERM drain the load balancer first, finish in-flight work inside the server.Shutdown(ctx) deadline, then align the grace period with that drain.
- Asked by: Ozan
- Answered: 2026-05-21
- Tags: #Performance, #Scaling, #Go
- https://www.muhammetsafak.com.tr/en/just-ask/graceful-shutdown-on-sigterm-for-autoscaled-apis/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/graceful-shutdown-on-sigterm-for-autoscaled-apis.md

### How do I choose the right composite index column order in PostgreSQL?

- Build one (user_id, status, created_at DESC) index with equality columns first and the sort column last, then drop the single-column indexes it now covers.
- Asked by: Doğa
- Answered: 2026-05-20
- Tags: #Performance, #PostgreSQL, #Database
- https://www.muhammetsafak.com.tr/en/just-ask/choosing-the-right-composite-index-order-in-postgresql/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/choosing-the-right-composite-index-order-in-postgresql.md

### How do I prevent a Redis cache stampede (thundering herd) — mutex lock or XFetch?

- A single-flight lock plus TTL jitter covers most cases; reach for XFetch only when recompute is truly expensive, and add stale-while-revalidate either way.
- Asked by: Cem
- Answered: 2026-05-19
- Tags: #Performance, #Redis, #Caching
- https://www.muhammetsafak.com.tr/en/just-ask/preventing-cache-stampede-with-mutex-locks-or-early-expiration/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/preventing-cache-stampede-with-mutex-locks-or-early-expiration.md

### How do I cut GC pressure in Go with sync.Pool and escape analysis under load?

- The enemy behind the pauses is allocation rate: kill the top allocator with pprof, pool the hot path with sync.Pool, and tune GOGC last, not first.
- Asked by: Arda
- Answered: 2026-05-17
- Tags: #Performance, #Go
- https://www.muhammetsafak.com.tr/en/just-ask/go-gc-pressure-sync-pool-and-escape-analysis-under-load/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/go-gc-pressure-sync-pool-and-escape-analysis-under-load.md

### How do I debug memory leaks under Laravel Octane (FrankenPHP)?

- Plot the memory_get_usage curve first, bisect service providers to narrow the culprit, then reset stateful singletons in Octane's hooks and clear statics.
- Asked by: Yiğit
- Answered: 2026-05-16
- Tags: #Performance, #Laravel, #Laravel Octane
- https://www.muhammetsafak.com.tr/en/just-ask/debugging-memory-leaks-under-laravel-octane-frankenphp/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/debugging-memory-leaks-under-laravel-octane-frankenphp.md

### Multi-tenant SaaS database isolation: separate DB, schema, or tenant_id?

- Database-per-tenant does not scale operationally at 10k; keep tenant_id on every table and bury isolation in Postgres Row-Level Security instead.
- Asked by: Berk
- Answered: 2026-05-15
- Tags: #Architecture, #Database, #Scaling
- https://www.muhammetsafak.com.tr/en/just-ask/multi-tenant-saas-database-isolation-for-10k-tenants/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/multi-tenant-saas-database-isolation-for-10k-tenants.md

### The payment webhook keeps re-sending the same notification; how do I set up idempotency?

- Verify the HMAC constant-time over the raw body, return 200 fast and enqueue the work, and let a UNIQUE constraint on event_id enforce once-only.
- Asked by: Sıla
- Answered: 2026-05-14
- Tags: #Architecture, #Security, #API
- https://www.muhammetsafak.com.tr/en/just-ask/webhook-idempotency-and-hmac-for-duplicate-payment-notifications/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/webhook-idempotency-and-hmac-for-duplicate-payment-notifications.md

### How do I peel the payment module off a PHP monolith with Strangler Fig?

- Shift payments at the gateway by 5/20/100 and validate in shadow first; the real work is splitting the tables, behind an anti-corruption layer and outbox.
- Asked by: Onur
- Answered: 2026-05-12
- Tags: #Architecture, #Microservices, #Go
- https://www.muhammetsafak.com.tr/en/just-ask/peeling-the-payment-module-off-a-php-monolith-with-strangler-fig/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/peeling-the-payment-module-off-a-php-monolith-with-strangler-fig.md

### If I build edge caching with Cloudflare Workers + KV, how do I do invalidation?

- The moment a price changes, write through to KV or purge the key in the same transaction or outbox; a short TTL and versioned keys are only the safety net.
- Asked by: Tolga
- Answered: 2026-05-11
- Tags: #Infrastructure, #Cloudflare, #Caching
- https://www.muhammetsafak.com.tr/en/just-ask/edge-caching-with-cloudflare-workers-kv-and-invalidation/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/edge-caching-with-cloudflare-workers-kv-and-invalidation.md

### How do I set up distributed tracing (OpenTelemetry) across microservices?

- Standardize on W3C Trace Context, leave propagation to the OTel SDK, and put traceparent in the queue message header, since that is where the chain snaps.
- Asked by: Ece
- Answered: 2026-05-09
- Tags: #Architecture, #Observability, #Microservices
- https://www.muhammetsafak.com.tr/en/just-ask/distributed-tracing-with-opentelemetry-across-laravel-and-go/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/distributed-tracing-with-opentelemetry-across-laravel-and-go.md

### WireGuard collides with Docker networks — how do I stabilize routing?

- This is an addressing-plan problem, not a routing bug: pin Docker's pool in daemon.json, cut AllowedIPs down to the DB subnet, make routes persistent.
- Asked by: Mert
- Answered: 2026-05-08
- Tags: #Infrastructure, #Networking, #Docker
- https://www.muhammetsafak.com.tr/en/just-ask/wireguard-and-docker-network-ip-conflicts-and-routing/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/wireguard-and-docker-network-ip-conflicts-and-routing.md

### How should I abstract the LLM provider (Ollama → Bedrock/OpenAI)?

- Build one narrow complete(prompt, opts) interface with three implementations picked by config, and treat context window, latency and cost as config.
- Asked by: Deniz
- Answered: 2026-05-06
- Tags: #Architecture
- https://www.muhammetsafak.com.tr/en/just-ask/abstracting-the-llm-provider-from-ollama-to-bedrock-or-openai/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/abstracting-the-llm-provider-from-ollama-to-bedrock-or-openai.md

### When moving local files to S3, is EFS a good interim step?

- Don't make EFS the interim step; switch to a Flysystem s3 disk, route reads and writes via Storage::disk(), and migrate with dual-read for zero downtime.
- Asked by: Kaan
- Answered: 2026-05-05
- Tags: #Architecture, #Infrastructure, #Scaling
- https://www.muhammetsafak.com.tr/en/just-ask/moving-local-files-to-s3-is-efs-a-good-interim-step/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/moving-local-files-to-s3-is-efs-a-good-interim-step.md

### For the message schema between Laravel and Go services, Protobuf or JSON Schema?

- For heavy Laravel-Go traffic pick Protobuf plus a schema registry, keep JSON Schema for light traffic, and deserialize into a typed DTO at the boundary.
- Asked by: Selin
- Answered: 2026-05-03
- Tags: #Architecture, #Microservices, #Go
- https://www.muhammetsafak.com.tr/en/just-ask/message-schema-between-laravel-and-go-protobuf-or-json-schema/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/message-schema-between-laravel-and-go-protobuf-or-json-schema.md

### Should I put a Kafka/Redis buffer between Fluent Bit and OpenSearch when shipping logs?

- Turn on Fluent Bit's filesystem buffer first; move to Kafka once 40k/s is permanent, and keep a Redis list only for logs you can afford to lose.
- Asked by: Burak
- Answered: 2026-05-02
- Tags: #Infrastructure, #Observability, #Apache Kafka
- https://www.muhammetsafak.com.tr/en/just-ask/should-i-put-a-kafka-buffer-between-fluent-bit-and-opensearch/
- Markdown: https://www.muhammetsafak.com.tr/en/just-ask/should-i-put-a-kafka-buffer-between-fluent-bit-and-opensearch.md
