← ByteDance Interview InsightsBackend Engineer

ByteDance·Backend Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Bytedance backend interview, one question on database fundamentals. Pretty standard stuff but they pushed a bit on the details.

Questions Asked (1)

Q1

Can you explain primary keys, foreign keys, and indexes in databases, and how they relate to each other?

Data ModelingTechnical Trade-offs
Author's notes

Covered the basics fine but stumbled a bit when trying to explain clustered vs non-clustered indexes without being asked.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining each concept clearly and concisely, then explain how they differ in purpose and implementation. Use a concrete example (e.g., users and orders tables) to illustrate their relationships and trade-offs, emphasizing real-world implications like performance and data integrity.

Pro tip: Mention that while primary keys and foreign keys enforce data integrity, indexes are primarily for performance—and that foreign keys often require indexes for efficient joins, but not all indexes are foreign keys. This shows you understand the nuanced interplay beyond textbook definitions.

1. Define primary keys

Explain that a primary key uniquely identifies each row in a table, must be unique and not null, and often uses an auto-incrementing integer or UUID. Mention its role in enforcing entity integrity.

2. Define foreign keys

Describe a foreign key as a column or set of columns that references a primary key in another table, enforcing referential integrity. Give an example like orders.user_id referencing users.id.

3. Define indexes

Explain that an index is a data structure (often B-tree) that speeds up data retrieval at the cost of additional storage and slower writes. Clarify that indexes can be created on any column(s), not just keys.

4. Explain relationships and trade-offs

Discuss how primary keys automatically create a unique index, foreign keys often benefit from an index for join performance, and indexes are independent of keys but can be used to enforce uniqueness. Highlight trade-offs: integrity vs. performance, write overhead vs. read speed.

5. Summarize with a practical example

Use a simple schema (e.g., users and orders) to show how primary keys, foreign keys, and indexes work together, and mention considerations like composite keys or covering indexes for backend engineering.

Key Points to Mention

  • Primary key enforces uniqueness and non-nullity; often auto-incremented or UUID.
  • Foreign key enforces referential integrity and can cascade updates/deletes.
  • Indexes improve read performance but add write overhead and storage cost.
  • Primary keys automatically create a unique index; foreign keys do not automatically create an index (in most databases).
  • Composite keys and composite indexes can be used for multi-column constraints and queries.
  • Trade-offs: over-indexing slows writes; under-indexing slows reads; foreign keys without indexes can cause slow joins.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.