Why Schema Design matters in LLD?
In an LLD interview, you aren't just writing classes; you are often asked how those objects would be stored. A poor schema leads to data inconsistency and slow queries, no matter how clean your Java code is.
1. From Objects to Tables
In Java, we use Composition and Inheritance. In Databases, we use Foreign Keys and Normalization.
The "Mapping" Rule of Thumb:
- Composition: Maps to a one-to-one or one-to-many relationship with a foreign key.
- Inheritance: Maps to "Table per Class" or a single table with a "Discriminator" column.
- Enums: Maps to strings or integer IDs.
2. Curriculum in this Module
- Theory: DB Modeling for LLD (Current Page)
- Lesson: API Contract Design - REST vs. GraphQL for LLD.
- Lesson: Idempotency in LLD - Ensuring safety in service methods.
- Curated Practice: Schema Drills - Modeling 5 complex systems.
3. Designing API Contracts
Your service interfaces should follow the "Principle of Least Astonishment":
- Use standard HTTP status codes (201 for Created, 400 for Bad Request).
- Keep requests small and specific.
- Avoid returning database entities directly; use DTOs (Data Transfer Objects).
Final Takeaway
Great LLD is a Contract. Your API and Schema define how your system interacts with the outside world and how it remembers its state.