Tell, don't ask 00:00:00 Make a prediction You will convert a check-then-set sequence into an operation that protects the owner's rule and still expose legitimate read-only questions. Two desk clerks both ask whether the last copy is free, and both hear yes. Can a later assignment of the borrowed flag prevent double checkout by itself? No. The check and change need one consistency boundary. Ask the owner to attempt checkout and return its result, rather than publishing two separate mutable steps. 00:00:31 Six sheep and one dog A shepherd asks a sheepdog to bring the flock home. Micromanaging each turn from a distant gate would require the shepherd to read every sheep's position and reproduce the dog's decisions. Tell the knowledgeable owner the outcome you need. The fact that callers may read information does not mean they should assemble a state change from exposed internals. Tell, don't ask is advice about where a decision lives. Asking: the caller reads values from an object, decides what they mean, and changes the object. Telling: the caller names the wish, and the object reads its own values, decides and changes itself. A rule that lives in callers lives in many places. A shop has a web page, an app and a phone desk. If each checks a voucher itself, three copies of the rule drift apart, and the fourth caller forgets one line. 00:01:26 Reserve the final book copy A clerk asks whether a copy is available and later sets its status to borrowed. Between those calls another clerk can make the same decision. Ask the owning component to check out the copy for this member in one operation. It checks the condition and applies the transition together. Two requests for one copy produce one loan and one refusal when the transition is made atomic. Merely renaming two unsafe operations will not make them atomic. Stop the two clients right after each asks whether the book is free. Both see yes. Resume the writes and two reservations appear. Place the check and transition together inside a shared reservation operation so that exactly one client can receive confirmation. 00:02:13 Keep useful questions A timetable screen asks when the next train leaves and displays the answer. That read is appropriate because the screen only needs information. If it also changes the timetable based on exposed internal fields, move the change behind the owner instead. Reading a departure time for display is useful and causes no ownership conflict. Reading availability and then independently writing a booking is different: someone else can change it in the gap. The distinction is whether the caller is reconstructing another owner's state transition. Simply putting a new name on a method does not make separate unsafe updates atomic. Test the overlapping requests in the actual ownership boundary. Read-only queries are appropriate for a display whose job is to show a departure time rather than to mutate the schedule. Redis: INCR. Reading a number, adding 1 and writing it back from a client loses updates. INCR tells the server to do it as one atomic step and answers with the new value. Java: ConcurrentHashMap.putIfAbsent. The documentation shows the ask version, containsKey and then put, and adds that the method does the same atomically. 00:03:30 Try an interview follow-up How do you send a command over a network? With a request id that stays the same for repeats. The owner stores the answer together with the change and returns it again. The sender has a timeout, a few tries, and a state unknown for the rest. A gate reads a ticket's status and writes used if it sees valid. Two gates can both read valid. Give the ticket service a check-in operation that enforces one transition at the shared storage boundary. The gate now handles accepted or already-used outcomes while the policy lives in one place. 00:04:08 What to take with you Find code that reads an object, decides, and writes back to the same object. Move the whole decision into one method of that object, and let it return a result. Questions stay welcome when they have no later action on the same object: screens, reports, decisions that belong to the caller or need several objects.