🎓 A1Learner
🔍
0 of 47 lessons completed

APIs and Data Models in Design Interviews

An API and data model answer is the part of a design interview where you name the operations a system offers and the records it stores. It comes after clarifying the problem and estimating scale, and it comes before scaling choices.

List the endpoints first

An endpoint list states what the system can do. Each row names one operation in plain words.

endpoints = [
    {"method": "POST", "path": "/notes", "use": "create a note"},
    {"method": "GET", "path": "/notes/42", "use": "read one note"},
    {"method": "GET", "path": "/notes", "use": "list notes"},
]
for e in endpoints:
    print(e["method"], e["path"], "->", e["use"])

Sketch one record

A record holds the facts one operation needs. Fields that no operation reads do not belong in the first sketch.

note = {"id": 42, "title": "Shopping", "body": "Buy milk", "owner": "ana"}
for key in ["id", "title", "owner"]:
    print(key, "=", note[key])

Separate required from optional fields

Required fields are the facts the system cannot work without. Optional fields can wait for a later version.

required = ["id", "owner", "body"]
optional = ["title"]
print("required:", ", ".join(required))
print("optional:", ", ".join(optional))

Example

print("API")
api = [("POST", "/notes"), ("GET", "/notes/7")]
for method, path in api:
    print(method, path)
print("MODEL")
fields = ["id", "owner", "body", "title"]
for field in fields:
    print("-", field)

Key points

  • API: the list of operations a client can ask the system to perform.
  • Endpoint: one operation, named by a method and a path, such as creating a note.
  • Data model: the shape of each stored record, with one field per fact.
  • Use an identifier field to point at one exact record among many.
  • The existing System Design courses are prerequisites for this lesson, and they cover the deeper storage and service topics.

The program prints the API first, then the model. Two endpoints cover creating and reading a note. Four fields describe one note record, and the title stays last because it is optional.

Note

keep the first version small, with only the operations the core use case needs.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Python Playground

Exercise

A design interview asks for a note service. Which step belongs in the API and data model part of the answer?