Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Book Upload and Search Service

Design a service where authors upload books with their details and readers search the catalog. Cover the API, the tables that hold books and files, and fast search.

Problem statement

Design a service where authors upload books and readers search for them. The design should cover the API, the tables that hold books and files, and the search that readers use.

For this exercise, assume an author signs in and uploads a book. A book has one file (PDF or EPUB, up to 200 MB) and its details. The details are a title, up to 10 author names, a language, a publication year, an optional ISBN, a description and up to 10 tags.

A book is not listed until the service has checked the file. The file must be a real PDF or EPUB and pass a malware scan. The service also pulls out a cover image and a page count.

The author can follow the book's status (uploading, checking, listed, or rejected with a reason), edit its details, replace its file, or remove the book. Nobody else can. When the author replaces the file, readers keep the old file until the new one passes the check, and the author follows the new file's status.

If the new file fails, the old one stays. An upload that is sent again, for example after the connection drops, must not create a second book. An author also cannot list the same file twice, even under two different books.

Readers, signed in or not, search the catalog by words in the title, the author names, the tags and the description. They can narrow results by language and by year, and get 20 results at a time, ordered by how well they match. They can open a book's page and download its file.

Only a listed book can be found, opened or downloaded.

Also assume the catalog holds 20 million books and 50,000 books are uploaded a day, with up to 20 uploads a second at peak. The average file is 5 MB. Searches peak at 2,000 a second. The 95th percentile (95 out of 100 searches) should be under 300 ms. Downloads peak at 1,000 a second.

A new or changed book should show up in search within 60 seconds of passing the check. A removed book should disappear from search and downloads within 60 seconds. Searching inside the text of a book, reading online, payments, recommendations, reviews, copy protection and use in more than one region are out of scope.

What to build

  1. An author uploads a book file with its details and follows its status until it is listed or rejected. Sending the same upload again never creates a second book, and one author never lists the same file twice.
  2. An author edits a book's details, replaces its file, or removes the book, and only the author can. A new file replaces the old one only after it passes the check.
  3. Readers search by words in the title, authors, tags and description, narrow by language and year, and get ranked results a page at a time.
  4. Readers open a book's page and download its file, but only while the book is listed.

At scale

  • For this exercise, assume the catalog holds 20 million books. 50,000 are uploaded a day, with up to 20 uploads a second at peak. The average file is 5 MB, and the limit is 200 MB.
  • For this exercise, assume searches peak at 2,000 a second, and each returns 20 results. The 95th percentile (95 out of 100 searches) should be under 300 ms.
  • For this exercise, assume a new or changed book shows in search within 60 seconds of passing the check. A removed book leaves search and downloads within 60 seconds.
  • For this exercise, assume downloads peak at 1,000 a second. The check of a file finishes within 5 minutes at the 95th percentile.