Learning Notes
I didn't know it was a whiteboard interview
A library database, two SQL questions, a checkout problem, an AWS diagram, and explaining tech to someone who isn't technical. I knew every idea they were testing. Under pressure, it didn't show.
I walked into an interview expecting a conversation about my experience. Instead, I was handed a marker and pointed at a whiteboard. For the first few seconds, my mind was as blank as the board.
The questions weren't hard. A small library database, two questions a librarian might ask, a checkout problem, an AWS diagram, and one about explaining a technical idea to someone who isn't technical. I knew every idea they were testing. But I hadn't written SQL by hand, with someone watching, in a long time, and I didn't know this was the format until I was standing there. It showed.
I'm writing it up for two reasons. Working through it properly is how I make sure I actually know it now. And if you have an interview coming up, these are good questions to practice, so you're not seeing them for the first time standing at a whiteboard.
So here's the interview again, the calm way: what I wrote, what was missing, and what I'd write now. Every answer below was run against a real Postgres database.
The library
The library has books, and each book has a genre, an author, a publisher and a shelf. Put all of that in one table, and "Jane Austen" gets typed out for every one of her books, and one "fiction" with a small f turns one genre into two. So each kind of thing gets its own table, stored once, and each book points to it by ID. On the board I did that, and it was right.
The core of it, cut down to what the questions need:
CREATE TABLE genre (
genre_id int PRIMARY KEY,
name text NOT NULL UNIQUE
);
CREATE TABLE author (
author_id int PRIMARY KEY,
first_name text,
last_name text NOT NULL
);
CREATE TABLE book (
book_id int PRIMARY KEY,
title text NOT NULL,
date_published date,
genre_id int NOT NULL REFERENCES genre
);
PRIMARY KEY, NOT NULL, UNIQUE and REFERENCES are rules the database checks on every write, so bad data can't get in. My SQL track's lessons on designing tables and joining tables go through them step by step.
There's one change from the board, and it comes up in Question 2.
Question 1: how many books of each genre?
What I wrote:
SELECT COUNT(book_id)
JOIN ... ON genre_id
FROM books
GROUP BY genre
The idea was right: join the books to their genres, and count per genre. But the JOIN came before the FROM, which SQL won't accept. And I counted without showing the genre, so the answer would have been a column of numbers with no labels.
What I'd write now:
SELECT g.name AS genre, COUNT(b.book_id) AS books
FROM genre g
LEFT JOIN book b ON b.genre_id = g.genre_id
GROUP BY g.genre_id, g.name
ORDER BY g.name;
genre | books
-----------+-------
Biography | 2
Fiction | 5
Mystery | 2
Poetry | 0
Two small choices make it right:
- Start from
genre, with aLEFT JOIN. With a plainJOIN, Poetry disappears, because it has no books to join to. A librarian wants to see Poetry: 0. COUNT(b.book_id), notCOUNT(*).COUNT(*)counts Poetry's empty row, and says it has 1 book. I ran it to check.
The question I should have asked first: "Do you mean titles, or copies?" A library with 15 copies of one book has 1 title and 15 books on the shelves. The next part of the interview had a table of copies, so they may well have meant copies. Asking takes five seconds, and it shows you think about what the data means, not only the syntax.
Question 2: the catalog, by author and publication date
What I wrote:
SELECT *
FROM books
ORDER BY author, publication_date
Close, but the book table doesn't have an author's name. It has an author's ID, a number. Ordering by that sorts authors by when they were added to the database, not by name.
What I'd write now:
SELECT a.last_name, a.first_name, b.title, b.date_published
FROM book b
JOIN book_author ba ON ba.book_id = b.book_id
JOIN author a ON a.author_id = ba.author_id
ORDER BY a.last_name, a.first_name, b.date_published;
Part of the output:
last_name | first_name | title | date_published
-----------+------------+-------------+----------------
Gaiman | Neil | Good Omens | 1990-05-01
Pratchett | Terry | Good Omens | 1990-05-01
Smith | Ali | Autumn | 2016-10-20
Smith | Zadie | White Teeth | 2000-01-27
- Join the author table to get the names, and sort by last name, then first name, then date, the way a library shelves books. Sorted by ID, Zadie Smith came before Ali, because she was added first.
- Name the columns, instead of
SELECT *. A catalog shows what a reader needs, not every ID.
And the change from the board: Good Omens appears twice, once under Gaiman and once under Pratchett, because it has two authors. On the board, the book table had one author column, and one column can't hold two authors. The fix is a table in between, with one row per book and author:
CREATE TABLE book_author (
book_id int REFERENCES book,
author_id int REFERENCES author,
PRIMARY KEY (book_id, author_id)
);
The question I should have asked: "Can a book have more than one author?" It's the classic design question hiding inside this one, and I walked straight past it.
Question 3: checking out three books at once
The board had this table:
Title ISBN Copies Copies already out
Book A 978-3-16-148410-0 15 10
Book B 567-3-16-148410-1 5 5
Book C 978-3-56-148740-3 30 23
The question: someone checks out all three in one transaction. What checks need to run?
What I wrote: a function that began if Title == "Book A". It would have worked perfectly, as long as the library only ever had one book.
What I'd write now: check every book first, and change anything only if they all pass.
def loan_out(catalog, isbns):
# 1. Validate everything first
for isbn in isbns:
book = catalog.get(isbn)
if book is None:
raise ValueError(f"{isbn} not found")
if book["copies"] - book["out"] < 1:
raise ValueError(f"{book['title']} unavailable")
# 2. Only if ALL pass, check them out
for isbn in isbns:
catalog[isbn]["out"] += 1
I ran it on the board's numbers: Book B unavailable, and nothing changed. All or nothing: Book B has none left, so the person gets none of the three, and a message saying why.
Then the follow-ups, which is where an interview like this really goes:
- The same book twice? Ask for Book C twice with one copy left, and each check sees one free copy. I ran it: 31 of 30 out. Count how many of each book are wanted (
collections.Counter), and check against that. - Two people at once? Both pass the check for the last copy, then both take it. Same result, 31 of 30. In a database, the check and the change go in one transaction, with the rows locked (
SELECT ... FOR UPDATE), and a rule on the table,CHECK (copies_out <= copies), as a backstop. - Is the data right? Two of the three ISBNs can't be real. Book B's starts with 567, and every ISBN-13 starts with 978 or 979. Book C's last digit is a check digit, worked out from the other twelve, and it should be 4, not 3. I'd flag them, not block the checkout.
- And the borrower? A valid card, under their limit, no fines.
The question I should have asked: "If one book isn't available, should the whole checkout fail?" Everything else follows from the answer.
Question 4: an AWS design, with the database on-premises
The fourth question was a design question, with one fixed rule: the database has to stay on-premises, in the company's own data center. I don't remember the exact wording, but the shape was: run the app in AWS, around a database that can't move. I drew a load balancer in front of two EC2 servers, one in each Availability Zone, connected through a transit gateway to the database.
One thing I did right: I checked the rule before drawing. Did the database really have to stay on-premises? It did. That's a real constraint, often for legal or cost reasons, or because everything else depends on it, and it changes the whole design.
What I'd change, now that the database is fixed in place:
Press Next to build it one piece at a time, or Show all. The whole diagram is also a single image.
- The transit gateway connects networks, not servers. On the board, I drew arrows from each server. In AWS, the whole VPC has one attachment.
- Two links, because one can break. Direct Connect as the main link, a Site-to-Site VPN as the backup. Two Availability Zones don't help if the one wire to the database is cut.
- The database is the remaining weak point. It needs a standby copy. And the app should keep the catalog in a cache, so if the link goes down, people can still browse while checkouts pause.
Question 5: explaining it to someone who isn't technical
One question had no whiteboard at all: explain a technical concept to someone who isn't technical.
What I did: I went on a rant about Microsoft Dynamics. It's a system I know well, and I had a lot to say about it. That was the problem. I was nervous, so I talked about what I knew best, in the detail I knew it in. The question wasn't "what do you know?" It was "can you make this make sense to someone else?"
What I'd do now: pick something everyone already understands, and hang the technical idea on it. For the cloud, that's somewhere to live:
| Where you live | What it is | You look after | Real examples |
|---|---|---|---|
| A house you built | On-premises: your own servers, in your own building | Everything, from the roof to the plumbing | A company's own data center |
| An empty rented apartment | IaaS (Infrastructure as a Service): the landlord owns the building, you rent the space | Your furniture: the operating system, software and data | Amazon EC2, Azure Virtual Machines |
| A furnished apartment | PaaS (Platform as a Service): the furniture is there, you bring your clothes | Just your own things: your code and data | AWS Elastic Beanstalk, Azure App Service, Heroku |
| A hotel | SaaS (Software as a Service): you just turn up and use it | Only how you use it | Gmail, Microsoft 365, Salesforce |
That takes thirty seconds. Then stop, and ask: "Does that make sense? Want me to go further on any of them?" If they want more, add one detail: in a hotel, you can't knock down a wall. That's why a company might choose the house, even though it's more work.
Three things made the difference, and my answer had none of them:
- Start from what they know, not from what you know.
- Keep it short, then check they're with you.
- Then one real example, to tie the picture back to the real thing.
What I'm doing differently
- Ask about the format. "Will it be a whiteboard, a shared editor, or a discussion?" Recruiters expect the question, and it's the difference between preparing for the right thing and the wrong one.
- Notice what the tools do for you. Like most engineers now, I write SQL in an editor that autocompletes it and underlines mistakes, with an AI assistant a keystroke away. That makes me faster at the job. It also means I hadn't written a query from memory, unaided, in a long time, and a whiteboard is exactly that.
- Practice the right way. I did practice beforehand, but the wrong way: reading answers, and typing queries in an editor that helped me. That builds recognition, the feeling of "I know this" when you see the answer. A whiteboard tests recall: producing it from nothing. So now I practice without the help, a few questions a week: read the question, close everything, write the answer on paper from memory, saying it out loud, and only then check it. PostgreSQL Exercises (opens in a new tab) and SQLBolt (opens in a new tab) are free, with answers to check yourself against. For the ideas behind them, my SQL track covers grouping, joins, table design and changing data safely, with a lesson on each.
- Say the assumptions first. Titles or copies? One author or several? All or nothing? Each of those changed an answer here. Asking them out loud also buys a few seconds to think, which under pressure is worth a lot.
Questions worth asking out loud
Each of these changes an answer above. Most design questions have one like them hiding inside.
- "Titles or copies?" What does "how many books" actually count?
- "Can a book have more than one author?" One column, or a table in between?
- "If one book isn't available, should the whole checkout fail?" All or nothing, or take what's there?
- "What if two people do this at the same moment?" Where's the lock?
- "Does the database have to stay where it is?" And if so, what happens when the link to it is down?
- "Who am I explaining this to?" Then start from what they already know.
It didn't go the way I wanted. But I know these answers better now than I would have if it had gone well.