← Bytedance Interview Insights

Bytedance·Backend Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Bytedance backend screen, just one database fundamentals question from what I can tell. Pretty standard stuff but worth writing down.

Questions Asked (1)

Q1

Can you explain what primary keys, foreign keys, and indexes are in a relational database?

Data ModelingTechnical Trade-offs
Author's notes

Covered the basics fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining each concept clearly and concisely, then explain their distinct roles in a relational database. Use a concrete example to illustrate how they work together, and highlight the trade-offs involved in their design and usage.

Pro tip: Emphasize that while primary keys and foreign keys enforce data integrity, indexes are primarily for performance—and that over-indexing can hurt write performance. Mentioning this trade-off shows you understand real-world database design beyond textbook definitions.

1. Define primary keys

Explain that a primary key uniquely identifies each row in a table, must be unique and non-null, and often uses an auto-incrementing integer or UUID.

2. Define foreign keys

Describe a foreign key as a column or set of columns that references the primary key of another table, enforcing referential integrity between related tables.

3. Define indexes

Explain that an index is a data structure (often a B-tree) that speeds up data retrieval operations at the cost of additional storage and slower writes.

4. Illustrate with an example

Use a simple schema like Users and Orders to show how a primary key in Users is referenced as a foreign key in Orders, and how an index on Orders.user_id speeds up joins.

5. Discuss trade-offs and best practices

Mention that primary keys ensure entity integrity, foreign keys enforce referential integrity, and indexes optimize read performance but add overhead to writes; advise indexing foreign keys and frequently queried columns.

Key Points to Mention

  • Primary key: unique, non-null, one per table, often auto-incremented or UUID.
  • Foreign key: references primary key in another table, enforces referential integrity, can have cascading actions.
  • Index: speeds up SELECT queries, especially on columns used in WHERE, JOIN, and ORDER BY; adds overhead to INSERT/UPDATE/DELETE.
  • Composite keys: primary keys and indexes can span multiple columns.
  • Trade-offs: indexes improve read performance but consume storage and slow down writes; foreign keys add integrity but can impact performance if not indexed.
  • Real-world example: In an e-commerce system, Users.user_id is primary key, Orders.user_id is foreign key, and an index on Orders.user_id improves join performance.

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