These Go database scenario questions describe real data problems, such as leaked connections, lost updates, slow queries and risky migrations. Each one asks what you would check, what you would change and how you would prove the fix. We gathered them from public interview lists and incident stories, then rewrote each one in our own words.
This post is questions only, so answer each one in your own words first. When you need help, read our post on databases, Go PostgreSQL with pgx and Go database migrations. Also, finish our post on API design scenarios first, because most API choices end in a query.
How to Use These Go Database Scenario Questions
For each of these Go database scenario questions, name the first metric or query you would check. Then describe the fix and how you would roll it out without downtime. Finally, mention what you would add so the problem never comes back.
The table below lists each section and its number of questions.
| Section | What it tests | Questions |
|---|---|---|
| Queries and pools | Rows, NULLs and connection limits | 15 |
| Transactions | Locks, races and money | 15 |
| Migrations | Schema changes and rollout | 15 |
| Performance | Indexes, plans and N plus 1 | 15 |
| Caching and reads | Redis, replicas and stale data | 15 |
| Incidents | Bad data, deletes and recovery | 15 |

Go Database Scenario Questions on Queries and Pools
Before you answer, study Go database tutorial. These Go database scenario questions start with the everyday bugs in query code.
- Your service runs out of connections after a few hours, so which missing call would you look for first?
- A handler returns early without closing rows, so how would you find every place like it?
- When a profile page crashes on users without a phone number, how would you fix the scan?
- A new teammate opens a fresh sql.DB in every request, so what would you change?
- Imagine db.Stats shows a high WaitCount at peak, then what would you tune?
- Your queries hang forever when the database is slow, so what is missing from each call?
- After a scale-up to 20 pods, the database refuses new connections, so how would you size the pool?
- A search query uses fmt.Sprintf with user input, so how would you fix it before a security review?
- When QueryRow finds no match, the API returns 500, so what should it return instead?
- A report loads 2 million rows into memory, so how would you stream them?
- Your code passes a list of 5000 IDs to an IN clause, so what problems can appear?
- When the load balancer drops idle connections, which pool setting helps?
- A query works in tests but fails in production with a type error on a column, so what would you check?
- Scenario: when connection errors appear only during database failover, how would you make the service recover?
- Scenario: when two services share one database and one slows the other, how would you separate them?
Go Database Scenario Questions on Transactions
Before you answer, study our post on databases again. Money and stock depend on correct transactions, so these Go database scenario questions go into detail.
- Two customers buy the last ticket at the same moment, so how would you stop overselling?
- A transfer debits one account and then the service crashes, so how would you keep balances correct?
- When a transaction calls a payment API in the middle, what can go wrong?
- Your code runs some queries on db and some on tx in the same flow, so what breaks?
- Imagine a serialization failure under load, then how would you retry safely?
- A long report transaction blocks writes for minutes, so what would you change?
- After adding SELECT FOR UPDATE, you see deadlocks, so how would you fix the lock order?
- A profile update loses changes when two tabs save at once, so which locking style would you pick?
- When an order and its outbox event must save together, how would you write it?
- Your service publishes an event before the commit and the commit fails, so what do consumers see?
- A batch job updates 100,000 rows in one transaction, so what risks does that bring?
- When a nested helper starts its own transaction, how would you share the outer one?
- A test leaves data behind because a transaction never ended, so how would you clean up?
- Scenario: when finance finds a balance that does not match the ledger, how would you investigate?
- Scenario: when a retry creates two orders for one payment, how would you make it idempotent?
Go Database Scenario Questions on Migrations
Before you answer, study Go database migrations. Schema changes can lock tables or break old code, so these Go database scenario questions test safe rollouts.
- Adding a column with a default locks a big table for minutes, so how would you add it safely?
- Your new code needs a column that the old code does not know, so in which order would you deploy?
- When you must rename a column used by three services, how would you do it without downtime?
- A migration fails halfway in production, so what are your next steps?
- Imagine an index on a 200 million row table, then how would you build it without blocking writes?
- Your team runs migrations at app start and two pods race, so what would you change?
- After dropping a column, an old pod crashes, so what step did the plan miss?
- You must add NOT NULL to a column that has old empty values, so how would you plan it?
- When a data backfill must touch every row, how would you batch it?
- Your local and production schemas drift apart, so how would you catch it?
- A rollback of a migration would lose data, so how would you plan for that?
- When two teams add migrations with the same number, what happens and how do you prevent it?
- A migration tool needs a lock table, so why does that matter?
- Scenario: when a migration that took 2 seconds in staging takes 40 minutes in production, what was different?
- Scenario: when a release needs both a schema change and a code change, how would you split it into safe steps?
Go Database Scenario Questions on Performance
Before you answer, study Go sqlc vs GORM and Go profiling with pprof. Slow queries hurt every user, so these Go database scenario questions focus on finding them.
- A list page makes 101 queries for 100 orders, so how would you fix it?
- Your slowest endpoint spends 90 percent of its time in one query, so what would you run first?
- When EXPLAIN shows a sequential scan on a big table, what would you check?
- A query uses LIKE with a leading wildcard and is slow, so what options do you have?
- Imagine an index that exists but the planner ignores, then what could cause that?
- Your bulk insert of 50,000 rows takes minutes, so how would you speed it up?
- After adding five indexes, writes become slow, so how would you choose which to keep?
- An ORM hides a query that loads every column, so how would you find and trim it?
- When COUNT on a big table is slow, how would you show totals in the UI?
- A report query competes with live traffic, so where would you run it instead?
- Your query is fast alone but slow under load, so what might be locking it?
- When pgx is faster than database/sql for one hot path, would you switch the whole app?
- Users search a JSON column often, so how would you index it?
- Scenario: when p99 latency jumps after a data load, how would you prove the query plan changed?
- Scenario: when the database CPU is at 95 percent, which queries would you tackle first?
Go Database Scenario Questions on Caching
Before you answer, study Go Redis caching and Go in-memory cache. Caches help reads but add new bugs, so these Go database scenario questions test both sides.
- Users see an old price for five minutes after an update, so how would you fix the cache flow?
- A popular key expires and the database gets a sudden spike, so which pattern would you add?
- When Redis goes down, the whole API fails, so how would you degrade gracefully?
- Your cache holds user data, so what must happen when a user deletes their account?
- Imagine a read replica that lags by ten seconds, then which requests must still read the primary?
- A user updates a profile and the next page shows old data, so how would you fix read-after-write?
- After adding a cache, memory on the Redis server keeps growing, so what would you check?
- When a cache hit rate is only 20 percent, what would you look at?
- A product page needs data from three tables, so would you cache the parts or the whole page?
- Your in-memory cache differs across pods, so how would you keep them in sync?
- When a cache stores not found results, how long should they live?
- A cache warmup after deploy slows the database, so how would you spread it out?
- Your team wants to cache everything, so how would you decide what is worth caching?
- Scenario: when a bug writes wrong data into the cache, how would you clear it safely?
- Scenario: when reads grow ten times in a month, would you add replicas, a cache or both?
Data Incidents and Recovery
Before you answer, think about real outages you have seen. These Go database scenario questions test calm, careful steps when data goes wrong.
- A bug sets every order status to cancelled, so what are your first three steps?
- Someone runs a DELETE without a WHERE clause in production, so how would you recover?
- When backups exist but nobody has tested a restore, what would you do this week?
- A migration corrupts a column for some rows, so how would you find and fix them?
- Imagine a service writes duplicate rows for a day, then how would you clean them up?
- Your database disk fills up at night, so what quick actions would you take?
- After a failover, some writes from the last seconds are missing, so how do you explain it?
- A customer asks for all their data under a privacy law, so how would you export it?
- When a code base mixes soft deletes and hard deletes, what problems appear?
- A long-running query blocks everything during an incident, so how would you stop it?
- Your audit log is missing for one hour, so how would you rebuild what happened?
- When a bad deploy writes wrong prices, how do you correct both data and cache?
- A team wants direct database access for quick fixes, so what guard rails would you add?
- Scenario: when an incident review shows no alerts fired for bad data, what checks would you add?
- Scenario: when a restore takes six hours, how would you shorten recovery time?
Code Reading Questions
Read each program carefully and predict the output before you run it. Then explain the result in your own words.
package main
import (
"errors"
"fmt"
)
type fakeTx struct{ log []string }
func (t *fakeTx) Commit() error { t.log = append(t.log, "commit"); return nil }
func (t *fakeTx) Rollback() error { t.log = append(t.log, "rollback"); return nil }
func withTx(tx *fakeTx, fn func() error) (err error) {
defer func() {
if p := recover(); p != nil {
tx.Rollback()
err = fmt.Errorf("panic: %v", p)
return
}
if err != nil {
tx.Rollback()
return
}
err = tx.Commit()
}()
return fn()
}
func main() {
a, b, c := &fakeTx{}, &fakeTx{}, &fakeTx{}
errA := withTx(a, func() error { return nil })
errB := withTx(b, func() error { return errors.New("stock too low") })
errC := withTx(c, func() error { panic("nil map") })
fmt.Println(errA, a.log)
fmt.Println(errB, b.log)
fmt.Println(errC, c.log)
}
- What does each line print, and how does the named result let the deferred func change the error?
- Why does the helper still roll back when the function panics?
The second program shows optimistic locking with a version number.
package main
import (
"errors"
"fmt"
)
var ErrStale = errors.New("stale version")
type Row struct {
Stock int
Version int
}
func update(r *Row, seen, newStock int) error {
if r.Version != seen {
return ErrStale
}
r.Stock = newStock
r.Version++
return nil
}
func main() {
row := &Row{Stock: 5, Version: 1}
a, b := *row, *row
errA := update(row, a.Version, a.Stock-1)
fmt.Println(errA, row.Stock, row.Version)
errB := update(row, b.Version, b.Stock-2)
fmt.Println(errB, row.Stock, row.Version)
}
- What do the two lines print, and why does the second writer fail?
- What should the second writer do next, and how would that look in SQL?
Quick Revision Table for Data Fixes
Use the table below as a final check before your interview. It maps common data symptoms to the first fix to try.
| Symptom | Likely cause | First fix |
|---|---|---|
| Pool exhausted | Rows or tx not closed | defer rows.Close, check stats |
| Overselling | Race on stock count | Row lock or version check |
| 101 queries per page | N plus 1 pattern | Join or batch load |
| Table locked by migration | Unsafe schema change | Expand, backfill, contract |
| Stale reads | Cache or replica lag | Invalidate or read primary |
| Duplicate rows | Retries without keys | Unique key and idempotency |
Also, many interviewers ask you to compare locking styles. The diagram below shows the difference side by side.

Official Resources
These official pages explain the tools behind these scenarios.
- Go documentation: Accessing relational databases
- Executing transactions
- Managing connections
- PostgreSQL: Using EXPLAIN
Quick Recap
- These Go database scenario questions cover pools, transactions, migrations, performance, caching and incidents.
- Close rows, pass a context and size the pool for every replica.
- Protect stock and money with row locks or version checks.
- Change schemas in small steps that old and new code can both handle.
- Find slow queries with EXPLAIN, and fix N plus 1 patterns early.
- Test restores, add data checks and keep fixes repeatable.
What’s Next?
By now, you have Go database scenario questions for the data problems real teams face. Practise your answers out loud, then check your progress in the Go interview topics study guide.
Next up: Go testing scenario questions


