Topic 1 Question #3
You designed a database for patient records as a pilot project to cover a few hundred patients in three clinics. Your design used a single database table to represent all patients and their visits, and you used self-joins to generate reports. The server resource utilization was at 50%. Since then, the scope of the project has expanded. The database must now store 100 times more patient records. You can no longer run the reports, because they either take too long or they encounter errors with insufficient compute resources. How should you adjust the database design?
- A.
Add capacity (memory and disk space) to the database server by the order of 200.
- B.
Shard the tables into smaller ones based on date ranges, and only generate reports with prespecified date ranges.
- C.
Normalize the master patient-record table into the patient table and the visits table, and create other necessary tables to avoid self-join.
- D.
Partition the table into smaller tables, with one for each clinic. Run queries against the smaller table pairs, and use unions for consolidated reports.
Answer: C
The root cause of the performance issue in this scenario is the original denormalized schema design that combines two logically distinct entities, patients and their visits, into a single table, requiring computationally expensive self-joins to generate reports. As the dataset grows 100x, self-joins on a single large table result in exponentially increasing query latency and resource consumption, as the database must scan the full table multiple times per query. The suggested answer, normalization, directly addresses this root cause by splitting the single denormalized table into separate, logically aligned tables (patient, visits, and other supporting tables) with defined primary and foreign key relationships. This eliminates the need for self-joins entirely, reduces redundant data storage, allows for targeted indexing of join keys, and drastically reduces the volume of data scanned during report generation. This approach is a scalable, cost-effective solution aligned with core data engineering schema design best practices, rather than relying on brute force infrastructure adjustments that do not resolve underlying inefficiencies. Option Analysis:
A. Incorrect. Adding 200x server capacity is a brute force, cost-ineffective approach that fails to address the root cause of the performance issue: inefficient self-joins resulting from poor schema design. As the dataset continues to grow over time, query performance will degrade further even with added capacity, making this an unsustainable solution that violates data engineering best practices for performance optimization.
B. Incorrect. Sharding by date range and restricting reports to predefined date ranges does not eliminate the performance overhead of self-joins on each individual shard, and unnecessarily limits business functionality by restricting report parameters. This approach avoids resolving the underlying schema flaw, so it is not an optimal or scalable solution.
C. Correct. Normalizing the single denormalized table into separate tables for patients, visits, and related entities removes the requirement for expensive self-joins entirely. Normalization reduces data redundancy, enables efficient indexing of primary and foreign key join columns, reduces the volume of data scanned during query execution, and scales sustainably as the dataset grows. This directly resolves the root cause of poor report performance, aligning with relational database design best practices for data engineering.
D. Incorrect. Partitioning the table by clinic does not eliminate the need for self-joins on each per-clinic table, so the core performance inefficiency remains. Additionally, union operations for consolidated reports add extra query overhead, and this approach does not address the fundamental flaw of the original denormalized schema design. Key Concepts:
1. Relational Database Normalization: The process of structuring a relational schema to reduce data redundancy and improve integrity by splitting large, multi-entity tables into smaller, logically distinct tables with defined foreign key relationships. Eliminating expensive self-joins via proper normalization is a core schema optimization skill for data engineers.
2. Root Cause Performance Optimization: A foundational data engineering principle that prioritizes resolving underlying design flaws such as inefficient schema over brute force infrastructure scaling to address performance issues, as this delivers more sustainable, cost-effective results.
3. Relational Schema Entity Alignment: Designing database tables to map to distinct business entities for example one table for patients, one for visits rather than combining multiple entities into a single table ensures efficient join operations and scalable performance as dataset size increases. References:
Google Cloud Best Practices for Relational Database Schema Design, Microsoft Learn Database Normalization Description,
https://learn.microsoft.com/en-us/office/troubleshoot/access/database-normalization-description