Skip to main content

Database and Storage Interview Questions for Data Engineers

Prepare for database fundamentals and analytical storage interviews with concise explanations, SQL and Python examples, practical trade-offs, and real-world design considerations.

In this chapter: OLTP vs. OLAP, columnar storage, indexes, partitioning vs. sharding, ACID transactions, relational vs. document databases, Parquet vs. CSV, and choosing formats for large analytical pipelines.

Quick Reference

ConceptRemember
OLTPOperational transactions, low-latency reads/writes, concurrency
OLAPAnalytical scans, aggregations, and historical reporting
Columnar formatRead selected columns efficiently; often compresses well
IndexFaster lookups at the cost of storage and write maintenance
PartitioningSplit a dataset into manageable/prunable pieces
ShardingDistribute data across nodes or servers
ParquetTyped, compressed columnar file format for analytics

1. What is the difference between OLTP and OLAP?

Suggested interview answer

OLTP (Online Transaction Processing) supports frequent, short operational transactions such as creating an order or updating an account. It prioritizes correctness, concurrency, and low-latency reads and writes. OLAP (Online Analytical Processing) supports analytical queries across large volumes of historical data, such as revenue trends or customer cohorts. OLTP systems commonly use normalized models; OLAP systems often use dimensional models, columnar storage, and large scans or aggregations.

Example

-- OLTP-style lookup: retrieve one order
SELECT order_id, status, total_amount
FROM orders
WHERE order_id = 10025;

-- OLAP-style aggregation: trend by month
SELECT DATE_TRUNC('month', order_date) AS month,
       SUM(total_amount) AS revenue
FROM fact_orders
GROUP BY DATE_TRUNC('month', order_date)
ORDER BY month;
What interviewers look for: Discuss workload, latency, concurrency, data model, and write/read patterns. Many architectures use OLTP systems for transactions and separate analytical platforms for reporting.

2. Why are columnar formats effective for analytical workloads?

Suggested interview answer

Columnar storage keeps values from the same column together, allowing engines to read only the columns required by a query. It can improve compression because values in a column often share similar types and patterns. Analytical engines can also apply vectorized processing and skip row groups or data pages using statistics. Columnar formats are especially effective for scans and aggregations, but are not universally best for point updates or single-row transactional access.

Example

-- Only two columns are needed for this aggregation.
SELECT product_category, SUM(net_sales_amount)
FROM fact_sales
WHERE order_date >= DATE '2026-01-01'
GROUP BY product_category;
What interviewers look for: Connect the query to projection pushdown, compression, predicate pushdown, statistics, and reduced I/O. Actual performance depends on file layout, query engine, and data distribution.

3. How do indexes improve query performance, and what are their trade-offs?

Suggested interview answer

An index is an auxiliary data structure that helps the database find rows without scanning the entire table. B-tree indexes can accelerate equality and range lookups; other index types suit different operators or data types. Indexes consume storage and must be maintained on inserts, updates, and deletes. Too many or poorly chosen indexes can slow writes, increase maintenance, and still be ignored by the optimizer when a scan is cheaper.

Example

-- Example syntax in many relational databases
CREATE INDEX idx_orders_customer_date
ON orders (customer_id, order_date);

SELECT order_id, order_date
FROM orders
WHERE customer_id = 42
  AND order_date >= DATE '2026-01-01';
What interviewers look for: Discuss selectivity, composite index column order, covering indexes, write overhead, and verifying the actual plan with EXPLAIN. Index behavior differs across database engines.

4. What is the difference between partitioning and sharding?

Suggested interview answer

Partitioning divides a table or dataset into smaller logical or physical pieces, often by date, range, list, or hash. Partitions may remain inside one database instance and help with pruning, maintenance, and lifecycle management. Sharding distributes data across separate database nodes or servers, often to scale storage and throughput horizontally. Sharding adds routing, rebalancing, cross-shard query, and operational complexity. The terms can overlap in some systems, so explain the architecture being discussed.

Example

-- Example conceptual partition filter
SELECT COUNT(*)
FROM events
WHERE event_date >= DATE '2026-10-01'
  AND event_date <  DATE '2026-11-01';

-- A shard key might route a customer to a node:
-- shard_id = hash(customer_id) % number_of_shards
What interviewers look for: Partitioning helps when a query can prune irrelevant partitions. Sharding is a distribution strategy across nodes and usually requires a shard key and cross-shard planning.

5. Explain ACID properties with a practical example.

Suggested interview answer

ACID stands for Atomicity, Consistency, Isolation, and Durability. Atomicity means all transaction steps succeed or none do. Consistency means constraints and invariants remain valid. Isolation controls how concurrent transactions interact. Durability means committed changes survive failures according to the database's guarantees.

Example

BEGIN;

UPDATE accounts
SET balance = balance - 100
WHERE account_id = 1;

UPDATE accounts
SET balance = balance + 100
WHERE account_id = 2;

COMMIT;
What interviewers look for: In a money transfer, both account updates should commit together. If the second update fails, rollback the transaction rather than leaving only the debit. Also validate sufficient funds and any business constraints.

6. When would you choose a relational database over a document database?

Suggested interview answer

Choose a relational database when the application benefits from a well-defined schema, joins across related entities, constraints, and multi-row transactions. It is often a good fit for financial transactions, order management, and systems with strong referential integrity requirements. A document database can be attractive for flexible, nested, aggregate-oriented records or rapidly evolving schemas. The choice depends on access patterns, consistency needs, query complexity, scaling, and operational expertise—not just whether data looks like JSON.

Example

-- Relational model: orders reference customers
SELECT o.order_id, c.customer_name, o.total_amount
FROM orders AS o
JOIN customers AS c
  ON o.customer_id = c.customer_id;
What interviewers look for: Explain how the application reads and writes data, what consistency it needs, how relationships are queried, and how schema evolution will be managed.

7. Why would you use Parquet instead of CSV?

Suggested interview answer

Parquet is a columnar, typed, compressed file format that supports metadata and row-group statistics. It often reduces storage and I/O for analytical queries that read selected columns. CSV is plain text, human-readable, and widely compatible, but has no built-in column types or compression requirement and often needs parsing and type inference. CSV can still be preferable for simple interchange, manual inspection, or systems that require it.

Example

# Python example: write/read Parquet with pandas
import pandas as pd

df = pd.DataFrame({
    "order_id": [101, 102],
    "amount": [250.0, 175.5],
    "country": ["IN", "DE"]
})

df.to_parquet("orders.parquet", index=False)
loaded = pd.read_parquet("orders.parquet")
What interviewers look for: Parquet is generally a strong choice for lakehouse analytics. CSV remains useful for portability and debugging. Consider compression, schema evolution, nested types, and downstream engine support.

8. How would you choose a storage format for a large analytical pipeline?

Suggested interview answer

Start from the workload and operational requirements. For analytical tables in a data lake, Parquet or ORC are common columnar choices. For streaming ingestion or event interchange, Avro or JSON may be useful because they support record-oriented messages or flexible payloads. If the pipeline needs transactional updates, concurrent writers, schema evolution, and time travel, consider a table format such as Apache Iceberg, Delta Lake, or Apache Hudi on top of data files. Also evaluate file sizes, partitioning, compaction, compression, compatibility, and governance.

Example

# Example: choose a typed columnar format for an analytical batch
import pandas as pd

df = pd.read_csv("raw_orders.csv")
df["order_date"] = pd.to_datetime(df["order_date"], errors="raise")
df["amount"] = pd.to_numeric(df["amount"], errors="raise")

df.to_parquet(
    "curated_orders.parquet",
    index=False,
    compression="snappy"
)
What interviewers look for: Describe the full lifecycle: ingestion, schema validation, file sizing, partition strategy, compaction, late data, incremental updates, consumer compatibility, and recovery.

Scenario-Based Practice Questions

1. A dashboard scans billions of rows but reads only three columns. What storage characteristics help?

Columnar storage can read only the required columns, while compression and row-group/page statistics may reduce I/O further. Partition pruning and predicate pushdown can help when filters align with the physical layout. Confirm with the query plan and scan metrics.

2. An index speeds up a report but slows ingestion. What would you investigate?

Review whether the index is selective and used by the query, whether its key order matches predicates, and whether redundant indexes can be removed. Every write may need to maintain indexes. Compare execution plans and write latency before and after changes.

3. A table is partitioned by date, but queries remain slow. Why?

Queries may not filter on the partition key, predicates may prevent pruning, partitions may be too small or too large, or the bottleneck may be joins, skew, or data movement. Inspect the actual plan and bytes or partitions scanned.

4. You need schema evolution and reliable updates in a data lake. Is Parquet alone enough?

Parquet is a file format, not a complete transactional table-management layer. Consider a table format such as Iceberg, Delta Lake, or Hudi if you need features such as atomic commits, concurrent writes, snapshots, schema evolution, or time travel.

Chapter Summary

  • Choose database architecture based on transactional versus analytical access patterns.
  • Columnar storage is efficient for many scans and aggregations because it reduces unnecessary I/O.
  • Indexes can speed reads but increase storage and write-maintenance costs.
  • Partitioning organizes data; sharding distributes data across nodes, with different operational trade-offs.
  • ACID properties help protect transactional correctness.
  • Choose relational or document storage based on relationships, constraints, query patterns, and consistency requirements.
  • Parquet is often a good analytical file format; choose broader table formats when transactional lakehouse capabilities are needed.
Practice challenge: Design storage for a pipeline ingesting order events from an API, landing raw data in a cloud object store, transforming it into analytical tables, and serving dashboards. Explain the file format, partition strategy, table format, database choice, and how you would measure performance.

Note: SQL and Python examples are illustrative. Syntax, indexing behavior, partitioning features, and transaction guarantees differ across database engines and platforms.

Comments

Popular posts from this blog

Tricky Questions or Puzzles in C ( Updated for 2026)

Updated for 2026 This article was originally written when C/C++ puzzles were commonly asked in interviews. While such language-specific puzzles are less frequent today, the problem-solving and logical reasoning skills tested here remain highly relevant for modern Software Engineering, Data Engineering, SQL, and system design interviews . Why These Puzzles Still Matter in 2026 Although most Software &   Data Engineering interviews today focus on Programming, SQL, data pipelines, cloud platforms, and system design , interviewers still care deeply about how you think . These puzzles test: Logical reasoning Edge-case handling Understanding of execution flow Ability to reason under pressure The language may change , but the thinking patterns do not . How These Skills Apply to Data Engineering Interviews The same skills tested by C/C++ puzzles appear in modern interviews as: SQL edge cases and NULL handling Data pipeline failure scenarios Incremental vs ...

Programs and Puzzles in technical interviews i faced

I have attended interview of nearly 10 companies in my campus placements and sharing their experiences with you,though i did not got selected in any of the companies but i had great experience facing their interviews and it might help you as well in preparation of interviews.Here are some of the puzzles and programs asked to me in interview in some of the good companies. 1) SAP Labs I attended sap lab online test in my college through campus placements.It had 3 sections,the first one is usual aptitude questions which i would say were little tricky to solve.The second section was Programming test in which you were provided snippet of code and you have to complete the code (See Tricky Code Snippets  ).The code are from different data structures like Binary Tree, AVL Tree etc.Then the third section had questions from Database,OS and Networks.After 2-3 hours we got the result and i was shortlisted for the nest round of interviews scheduled next day.Then the next day we had PPT of t...

Decorators in Python

Decorators provide additional functionality to the functions without directly changing their definition of them. Basically, it takes the functions as an argument, adds functionality to them, and returns it.  Before diving deep into the concept of Decorators, let's first try to understand  What are functions in Python and what is an inner function? In Python everything is Objects, be it Class, Variables, and Functions . So functions are python first-class objects that can be used or passed as an argument. You can store the functions in variables, you can pass a function to another function as parameters, and you can also return the function from the function. Below is one simple example where we are treating functions as objects . def make_me_lowercase ( str ): return str .lower() print (make_me_lowercase( "HELLO World" )) copy_of_you = make_me_lowercase print (copy_of_you( "HELLO World" )) The output of the above calls for both the functio...