Database Selection and Trade-offs Questions
Choosing the right database and data platform for a workload: relational versus NoSQL versus specialized stores, managed versus self-hosted, and matching technology to consistency, scale, cost, and query or access-pattern needs. Covers OLTP versus OLAP and transactional-versus-analytical workload splits, polyglot persistence across multiple data stores, structuring an ambiguous selection prompt, naming trade-offs, and defending a recommendation to stakeholders.
Explain the CAP theorem and its practical implications when selecting a distributed database. Give concrete examples of systems that prioritize different trade-offs (for example Cassandra, PostgreSQL clusters, DynamoDB Global Tables) and describe how those choices affect availability and consistency during network partitions.
Sample Answer
Direct answer
The CAP theorem says that during a network partition (a period where some nodes can't communicate with others), a distributed system can keep serving strong consistency (every read reflects the latest committed write) or availability (every request gets a non-error response), but not both at once; it has to choose. Since networks will partition eventually regardless of design, the real, practical question a database selection has to answer is not "CP or AP in the abstract" but "when this system splits, which side loses service, and for how long, and does that match what this workload can tolerate."
Structured elaboration
- Cassandra: availability-favoring (AP) by default. During a partition, each side keeps accepting reads and writes, with per-query tunable consistency levels (for example
ONEorQUORUM, how many replicas must acknowledge before a request succeeds). Replicas that fell out of sync heal afterward through mechanisms like hinted handoff (a reachable node temporarily stores a write meant for an unreachable replica and forwards it once that replica comes back) and anti-entropy repair (a background process that compares replicas against each other and reconciles any differences it finds). The trade is that a client can observe stale or conflicting data during and shortly after a partition, in exchange for both sides of the split continuing to serve traffic. - Postgres clusters (a primary with synchronous or semi-synchronous streaming replication, typically managed by an orchestrator like Patroni): consistency-favoring (CP) by design. A synchronous-replication setup will block or fail a write rather than let the primary and a replica silently diverge, and failover tooling generally fences off a partitioned-away node instead of letting it keep accepting writes as a second primary, which would risk split-brain (two nodes both believing they are the authoritative writer). That fencing is what makes it CP: the minority side of a partition becomes unavailable rather than inconsistent.
- DynamoDB Global Tables: has shipped both trade-off points as explicit, named modes. The original design, multi-Region eventual consistency, is AP: each region accepts writes independently, replication catches up asynchronously, and a region cut off by a partition keeps serving local reads and writes, resolving conflicting updates from different regions with a last-writer-wins rule. As of June 2025, AWS added multi-Region strong consistency (MRSC) as an opt-in mode: a write is synchronously replicated to at least one other of exactly three configured regions before it acknowledges, and reads return the latest version, moving that table's behavior toward CP (a write needs a reachable quorum of regions, so an isolated region alone can't accept writes), and giving up the transaction application programming interfaces (APIs) as the cost of that stronger guarantee. This is a clean, current illustration that CAP behavior is a configuration choice a specific product exposes, not a fixed label stuck to a product name.
Worked example
A three-region Cassandra ring loses connectivity between one region and the other two for several minutes. Application writes hitting the isolated region with a local quorum (a majority of that region's own replicas) keep succeeding, because Cassandra is AP: it doesn't require agreement from the unreachable regions. A client reading from one of the other two regions during that window may not yet see the isolated region's writes, and won't until the partition heals and repair mechanisms replay the missed updates, an inconsistency window bounded by however long the partition actually lasts, not by any fixed number the system guarantees in advance.
Trade-offs & pitfalls
"AP" does not mean "no consistency guarantees ever"; it means consistency is negotiated per operation or achieved eventually, rather than enforced synchronously on every write. "CP" systems are not unavailable in normal operation; they are only unavailable specifically to the minority side of an active partition. A common pitfall is treating CAP as a complete design theory: it says nothing about the latency cost of staying consistent during ordinary, non-partitioned operation, which is a separate and often more frequently relevant trade-off (the PACELC framework extends CAP to cover exactly this: even without a partition, a system still has to choose between lower latency and stronger consistency on every single request, a trade-off CAP alone is silent on).
Case study: Create a decision framework a Systems Engineer would use to decide between a managed database service (e.g., RDS/Cloud SQL) and a self-managed database on VMs for a critical application. Cover criteria: performance, customizability, operational burden, compliance, HA/failover semantics, backup/recovery, TCO over a 5-year horizon, and vendor lock-in. Propose scoring categories and show sample scoring for a workload that requires moderate customization and strong compliance needs.
Sample Answer
Direct answer
Build a weighted scoring rubric across the eight named criteria, weight compliance and operational burden highest for a workload that explicitly names strong compliance needs, and score each option with evidence rather than impression. For a workload needing moderate (not extreme) customization, a managed service usually wins once operational burden and compliance are weighted honestly, unless a specific compliance control the vendor cannot attest to forces a self-managed deployment.
Structured elaboration
Scoring categories and weights
| Criterion | Weight | Managed service, what a 5 looks like | Self-managed, what a 5 looks like |
|---|---|---|---|
| Performance | 10 | Meets the workload's latency and throughput (requests or data processed per unit time) targets on a right-sized tier | Fully tuned to the exact hardware and workload, no vendor abstraction overhead |
| Customizability | 10 | Extensions and configuration the vendor exposes cover every requirement | Full control of OS, kernel parameters, extensions, and storage layout |
| Operational burden | 20 | Patching, backups, and failover are automated and require no dedicated headcount | A dedicated, capable operations function exists and is funded |
| Compliance | 25 | Vendor certifications (SOC 2, PCI DSS, or the specific regime that applies) cover the controls this workload needs, with a shared-responsibility boundary that's actually documented | The organization can build, evidence, and pass an audit on every required control itself |
| HA/failover semantics | 15 | Automated, tested failover meets the required recovery time objective (RTO) without manual intervention | A built and drilled failover process meets the same RTO |
| Backup/recovery | 10 | Automated point-in-time recovery (PITR) meets the recovery point objective (RPO) | A built, tested backup and restore pipeline meets the same RPO |
| TCO (Total Cost of Ownership) over 5 years | 5 | Ongoing service fees stay below the fully-loaded cost of headcount plus infrastructure for the alternative | Infrastructure cost stays below vendor fees even after accounting for headcount |
| Vendor lock-in | 5 | Data export and open formats make leaving realistic | Full ownership of the stack, migration is a hardware change, not a vendor change |
The weights encode the workload's own stated priorities: compliance (25) and operational burden (20) dominate because this is described as a critical application with strong compliance needs and, implicitly, a team that is not purpose-built to run a database platform.
Worked example
For a workload needing moderate customization and strong compliance, one honest scoring pass (1 to 5 per option per criterion):
Totaloption=∑i=18wi×si
| Criterion | Weight | Managed score | Self-managed score |
|---|---|---|---|
| Performance | 10 | 4 | 4 |
| Customizability | 10 | 3 | 5 |
| Operational burden | 20 | 5 | 2 |
| Compliance | 25 | 4 | 3 |
| HA/failover | 15 | 5 | 3 |
| Backup/recovery | 10 | 5 | 3 |
| TCO (5yr) | 5 | 3 | 3 |
| Vendor lock-in | 5 | 2 | 5 |
Managed total: (10x4) + (10x3) + (20x5) + (25x4) + (15x5) + (10x5) + (5x3) + (5x2) = 40 + 30 + 100 + 100 + 75 + 50 + 15 + 10 = 420.
Self-managed total: (10x4) + (10x5) + (20x2) + (25x3) + (15x3) + (10x3) + (5x3) + (5x5) = 40 + 50 + 40 + 75 + 45 + 30 + 15 + 25 = 320.
Out of a maximum possible 500 (weights sum to 100, times a max score of 5), managed scores 420, 84%, and self-managed scores 320, 64%. Managed wins here specifically because compliance and operational burden, the two heaviest weights, are also where managed scores highest and self-managed scores lowest; the result would flip if compliance had to score low for managed (say, a control genuinely unavailable from any vendor) or if operational burden scored high for self-managed (an existing, funded DBA team).
Trade-offs & pitfalls
A scoring model is only as honest as its inputs: scoring every criterion from memory rather than evidence (an actual compliance attestation checked against the specific regime, an actual measured operational-hours estimate) turns the exercise into a way of pre-justifying a decision already made rather than making one. Weights matter more than most people expect: two reviewers scoring identically but weighting compliance at 10 instead of 25 will reach opposite recommendations, so the weights themselves need to be agreed and written down before scoring starts, not adjusted afterward to match a preferred answer.
As a data scientist working with production systems, explain the differences between OLTP and OLAP systems. Cover typical workload patterns (single-row reads/writes vs large analytic scans), latency and throughput expectations, storage formats (row vs columnar), indexing/partitioning implications, and name one concrete technology choice for each. Give a short example of when to route incoming application events to OLTP versus OLAP.
Sample Answer
Direct answer
Online transaction processing (OLTP) systems are optimized for many small, latency-sensitive, single-row reads and writes wrapped in short transactions (create an order, update an account balance); online analytical processing (OLAP) systems are optimized for read-heavy, large aggregate scans across millions of rows for reporting and analysis (total revenue by region last quarter). These two access patterns pull a storage engine's design in opposite directions, which is why production systems typically end up running one engine of each kind rather than asking a single engine to do both well.
Structured elaboration
| OLTP | OLAP | |
|---|---|---|
| Typical query | Single-row read/write by key | Aggregate scan across many/all rows |
| Concurrency | Many concurrent short transactions | Fewer, longer-running queries |
| Latency expectation | Milliseconds, per operation | Seconds, but over far more data per query |
| Storage format | Row-oriented (a full row stored together, cheap to fetch/update one record) | Columnar (each column stored together, cheap to scan and compress one column across billions of rows) |
| Schema shape | Normalized (minimizes duplication, keeps single-row writes cheap and consistent) | Often a star schema: a central fact table of measurable events (orders, clicks) surrounded by dimension tables (customer, product, time), because denormalized wide rows avoid expensive joins during large scans |
| Indexing / partitioning | Selective B-tree indexes (a sorted, tree-shaped index structure that lets the database jump directly to a matching row instead of scanning the whole table) on primary/foreign keys for fast point lookups | Columnar compression, block-level skip metadata, and time/date partitioning to prune scanned data, rather than row-level indexes |
| Concrete technology | Postgres, MySQL | Snowflake, BigQuery, Redshift |
Tying this to machine learning task types, since the systems a workload touches change with the task: model training reads large historical feature sets, which is OLAP-shaped access (broad scans across many rows, well served by columnar compression); real-time feature lookups for online inference are OLTP/key-value-shaped (single-row, low-latency point lookups by entity id, where a training-oriented columnar engine would be a poor and slow fit); reporting on model performance over time is OLAP-shaped aggregation again.
Worked example
An e-commerce order platform's order-creation write (decrement inventory, insert the order row, update the account balance) must be OLTP: transactional, immediately consistent, single-row-focused, and fast enough not to make the customer wait. That same committed order event is then copied asynchronously (via a change-data-capture or extract-transform-load pipeline) into an OLAP warehouse's fact table, where it feeds two different consumers from one denormalized table: a nightly batch job computing "daily revenue by region" for finance, and a near-real-time executive dashboard that incrementally refreshes every few minutes from the same fact table without touching the live order-processing database at all. Routing the write to OLTP and the read-heavy reporting to OLAP is what lets both jobs run without contending for the same locks and buffer-pool space the checkout flow needs.
Trade-offs & pitfalls
Running analytic aggregate queries directly against the OLTP database competes for the same resources (locks, cached pages) the live transactional workload needs, and a row store's full-row storage makes scanning many rows for just a few columns far more I/O-expensive than a columnar engine built for exactly that. Conversely, forcing single-row transactional writes through an OLAP engine designed for batch loads produces poor per-write latency and weak concurrent-update isolation guarantees. A common pitfall is assuming a full warehouse and pipeline are needed from day one, when an early-stage product's reporting needs are often served adequately by a read replica (a synced copy of the database that read-only queries can hit without competing with the primary) or a materialized view (a precomputed, stored snapshot of a query's result that is refreshed periodically instead of recalculated on every request) on the OLTP database itself.
When should a customer choose a managed database service versus self-managing databases on VMs or on-prem? Discuss tradeoffs across operational burden, total cost of ownership, customizability, compliance and auditability, upgrade control, and vendor lock-in. Provide decision criteria for a heavily regulated financial firm.
Sample Answer
Direct answer
For a heavily regulated financial firm, default to a managed database service from a provider holding the specific compliance certifications the regulator actually requires, for example SOC 2 Type II (an independently audited report confirming a provider's security controls held up over a period of months, not just on the day of a single check), PCI DSS (the Payment Card Industry Data Security Standard, the required control set for anyone storing or processing card payment data) for payment data, and any jurisdiction-specific attestations. Matching a large provider's patching cadence, tested backups, and audit tooling in-house is a cost few firms should choose to carry. Self-hosting only earns its keep when a specific, NAMED constraint forces it: a data-residency rule the provider cannot satisfy in-region, a mandated on-premises boundary, or a genuinely required customization blocked by the managed offering's extension allowlist.
Structured elaboration
Operational burden. Managed services absorb patching, backup execution, and failover mechanics. Self-hosting puts all of that on the firm's own team, and in a regulated environment that work itself becomes something the firm must prove happened on schedule, patches applied, backups actually tested, access controlled, which is strictly more work than performing the operations alone.
Total cost of ownership. Instance or license cost is usually the smaller piece; staffing, around-the-clock on-call coverage, security engineering, audit-evidence collection, dominates at real scale. A regulated firm pays for a compliance function regardless of hosting model, so self-hosting does not remove that cost, it adds the operational cost a managed service would otherwise have absorbed on top of it.
Customizability. This is the strongest genuine case for self-hosting. If the workload needs a storage engine, extension, or kernel-level tuning a managed offering's allowlist truly does not support, self-hosting is the only path. Verify the actual allowlist of the specific offering being evaluated first, because many assumed gaps turn out to be covered once checked, major managed PostgreSQL offerings, for instance, support extensions such as PostGIS (adds geographic and spatial data types and queries) and pg_cron (runs scheduled jobs inside the database itself), and increasingly let teams register their own sandboxed, trusted extensions.
Compliance and auditability. This cuts both ways, and it is the crux of "heavily regulated." A managed provider ships a shared-responsibility model with independently audited controls for the infrastructure layer, physical security, hypervisor isolation, patching SLAs, that a firm would otherwise have to build and prove itself. What the firm still owns regardless of hosting model is access control, data classification, encryption key management, many managed offerings support customer-managed keys, and query-level audit logging. Self-hosting does not remove these obligations; it just removes the second party who is also independently accountable for the infrastructure half.
Upgrade control. Self-hosting lets a firm pin an engine version indefinitely, relevant if a regulator requires documented change-control sign-off before any upgrade. Managed services generally enforce a maximum supported-version window and can push an upgrade on the provider's own timeline, which some regulated environments genuinely cannot accept without a formal exception process. This is a real, specific reason a firm might self-host one particular workload while running everything else managed.
Vendor lock-in. A managed offering of an open, widely implemented engine, managed PostgreSQL or MySQL, keeps the firm able to migrate to another provider or self-host later with a dump and restore plus a connection-string change. A proprietary, managed-only engine with no open equivalent makes that exit materially harder, which matters more for a regulated firm that may face a regulator-mandated provider change on a timeline it does not control. Mitigate by preferring managed offerings of open engines where the workload allows it, and by pricing lock-in risk into the decision from the start, not discovering it after committing.
Worked example
The firm's core ledger, subject to the heaviest audit scrutiny, is a strong candidate for managed PostgreSQL, or a similarly open, widely audited managed engine, from a provider holding the required certifications, with customer-managed encryption keys and query-level audit logging enabled, because none of the named regulatory concerns, residency, a truly unsupported customization, a change-control-incompatible upgrade cadence, apply to a standard ledger workload. A separate workload with a genuine on-premises data-residency boundary the provider cannot satisfy in-region is the one piece that goes self-hosted, decided workload by workload rather than as a single all-or-nothing policy.
Trade-offs and pitfalls
A pitfall is treating "regulated industry" as an automatic vote for self-hosting. In practice it more often argues for managed, because the provider's independently audited controls reduce what the firm itself must prove, while self-hosting concentrates the entire audit burden internally without necessarily buying more actual security.
A second pitfall is assuming a specific extension or customization gap exists without checking the current allowlist of the specific offering being evaluated. These change frequently, and an outdated assumption can drive an unnecessary, expensive self-hosting decision.
What would push the recommendation further toward self-hosted: a genuine, named, unwaivable regulatory requirement, verified against the actual regulation text rather than a general impression of risk. That is the one class of reason strong enough to accept the operational and audit burden self-hosting adds.
As an SRE, explain the operational differences between relational databases (e.g., PostgreSQL) and NoSQL stores (e.g., Cassandra, DynamoDB). Focus on availability, consistency, scaling patterns, backup/recovery, schema evolution, and common operational pitfalls. Give concrete examples of workloads where you'd choose one over the other and why, and describe the SRE operational changes required for each choice.
Sample Answer
Direct answer
Running Postgres and running Cassandra or DynamoDB in production are operationally different jobs, not just different query languages: a relational engine concentrates availability risk on a single primary that must be failed over correctly, while a leaderless or managed NoSQL store spreads both the write path and the failure domain across many replicas, trading "one thing to get right" for "many things that must stay in agreement."
Structured elaboration
| Dimension | Relational (Postgres) | NoSQL (Cassandra / DynamoDB) |
|---|---|---|
| Availability model | Single-writer primary plus replicas; failover needs orchestration (for example Patroni plus a consensus store) to promote a replica without a split-brain | Multi-writer or leaderless quorum (Cassandra) or fully managed multi-active partitions (DynamoDB); no single node's failure blocks writes |
| Consistency model | Strong by default on the primary | Tunable per query (Cassandra) or eventual-by-default with optional strong reads (DynamoDB) |
| Scaling pattern | Vertical plus read replicas; horizontal write scaling needs manual sharding | Horizontal partition-key sharding built in from the start |
| Backup / recovery | Point-in-time recovery via write-ahead log (WAL) replay or continuous archiving: a well-understood, single-timeline process | Per-node snapshots (Cassandra) that must be restored consistently across the whole ring, more moving parts to get right; DynamoDB backups are fully managed but restore into a new table, changing the operational runbook |
| Schema evolution | ALTER TABLE is a coordinated, sometimes-blocking data-definition operation that needs careful sequencing on a large table | Adding a new attribute to new writes needs no blocking migration; the trade is that the application, not the engine, owns enforcing the new field's presence and shape |
| Common pitfalls | Connection exhaustion under load without pooling; a bad migration locking a hot table | Hot partitions from a poorly chosen partition key; underestimating repair/anti-entropy scheduling (Cassandra), the background jobs that compare replicas against each other and resync any that have drifted out of agreement, or throttling under provisioned-capacity limits (DynamoDB) |
Worked example: an analytics platform ingesting structured application logs alongside semi-structured event payloads (variable JSON fields per event type), at high, bursty write volume, feeding downstream dashboards.
- Postgres: schema evolution becomes a real risk here, since a blocking
ALTER TABLEon a huge, actively-written logs table needs careful online-migration tooling to avoid an outage, and a single-primary availability model is exposed to bursty write spikes overwhelming one node. - Cassandra or DynamoDB: absorbs schema evolution and horizontal write scale comfortably, but the team now owns quorum and repair health (self-managed Cassandra) or partition hot-key and capacity-unit monitoring (DynamoDB), plus a multi-node backup and restore runbook instead of a single-timeline one.
- A columnar analytical engine (BigQuery or ClickHouse), purpose-built for exactly this log/event shape: schema evolution is cheap (new nullable columns), ingestion is typically a batch or streaming insert application programming interface (API) rather than a transactional write path, and BigQuery in particular removes cluster-capacity ownership entirely (a fully managed, serverless engine), while ClickHouse trades that operational simplicity away for lower cost and more control, at the price of the team owning background merge and compaction health themselves (compaction: periodically combining and rewriting many small stored files into fewer, larger ones to keep storage and query performance from degrading).
The operational changes each choice actually requires of the team:
- Postgres: own failover orchestration and rehearsed point-in-time recovery drills, connection pooling to avoid exhaustion, and careful sequencing of schema migrations.
- Cassandra / DynamoDB: own repair and anti-entropy scheduling (self-managed Cassandra) or capacity and throttling monitoring (DynamoDB), design explicitly around avoiding partition hot-keys, and rehearse multi-region backup and restore.
- Columnar OLAP (BigQuery / ClickHouse): own ingestion pipeline health and backpressure, and for self-managed ClickHouse, background merge and disk-space monitoring; for managed BigQuery, own query-cost and slot monitoring instead of cluster health.
Trade-offs & pitfalls
The most common operationally-visible pitfall is assuming "the NoSQL store scales itself" only covers scaling THROUGHPUT, not scaling the TEAM'S operational knowledge; a Cassandra ring with an inconsistent replica count after a bad node decommission is a genuinely different, often less familiar, failure class than "the Postgres primary died," and backup and recovery drills need to be rehearsed per system rather than assumed to transfer from one engine's runbook to another's.
Unlock Full Question Bank
Get access to all 13 Database Selection and Trade-offs interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.