Design a Bookshelf with Book CRUD and a Stable Bookmark
Company: Google
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Onsite
# Design a Bookshelf with Book CRUD and a Stable Bookmark
Design an object-oriented bookshelf that supports creating, reading, updating, and deleting books while maintaining a bookmark.
The source does not define whether the bookmark identifies a book, a position within a book, or a position on the shelf. Begin by clarifying that semantic. Then choose one contract, explain the classes and operations, and define what happens to the bookmark when books are reordered, updated, or deleted.
### Clarifying Questions to Ask
- Does the bookmark point to a stable book ID, a page or offset inside that book, or an index between books?
- Can the shelf be reordered, and may book IDs change during an update?
- Can there be multiple bookmarks or only one?
- What should deletion of the bookmarked book do: clear the bookmark, reject deletion, or move it deterministically?
- Must state persist across restarts or support concurrent users?
### What a Strong Answer Covers
- Stable identity separated from mutable title, content, and shelf position.
- A bookshelf aggregate, book repository or collection, ordering structure, and bookmark value object.
- Explicit CRUD preconditions and deterministic bookmark behavior for update, reorder, and delete.
- Encapsulation that prevents a dangling bookmark and transactional persistence when needed.
- Boundary cases such as an empty shelf, duplicate IDs, deleting the only book, and invalid offsets.
### Follow-up Questions
1. How would you support one bookmark per user without copying the book collection?
2. What changes if a book update inserts pages before the bookmarked location?
3. How would two concurrent requests reorder the shelf without losing either change?
Quick Answer: Design an object-oriented bookshelf with book CRUD, stable ordering, and explicit bookmark behavior. The solution separates immutable identity from position, handles updates and deletion without dangling references, and covers persistence, optimistic concurrency, content-offset migration, reordering, and edge cases.