Lesson 5 of 17 2 min

LLD Masterclass Module 3: Schema & API Design

Learn how to design robust database schemas and API contracts for your LLD projects. Master the transition from objects to tables.

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

  1. Theory: DB Modeling for LLD (Current Page)
  2. Lesson: API Contract Design - REST vs. GraphQL for LLD.
  3. Lesson: Idempotency in LLD - Ensuring safety in service methods.
  4. 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.

Want to track your progress?

Sign in to save your progress, track completed lessons, and pick up where you left off.