Concept Cases

Shopping cart, search, login, inventory, pagination, todo list, rate limiter, job queue — each taken from "I need X" through meaning, state, operations, rules, examples, structure, pseudocode and code, only as far as its version justifies.

Case: Implement a Shopping Cart
▶ lab

Start with "implement a shopping cart" and nothing else. Meaning, state, operations, rules, examples, data structure, pseudocode, code, tests, persistence, API, frontend, failures — in that order, each derived from the one before.

Q · You are told "implement a shopping cart" with no further detail and you have never written one. How do you get from that sentence to working, explainable code without receiving the code from somewhere else?
Case: Implement Search
▶ lab

"Search products by name" is, in V1, a loop over products checking whether a name contains the query. Meaning, state, operations, rules and examples first; database search, a full-text index and a search engine only when a measured reason arrives.

Q · Someone says "we need search" and you picture a search engine. What is the smallest thing that is honestly search, how do you derive it, and what would have to be true before the bigger things are justified?
Case: Implement Login

Login is: credentials arrive, the identity is verified, an authenticated session is created, and future requests are associated with it. The concept and its operations are derivable; the security-sensitive mechanics — hashing, tokens, CSRF — are learned from Security Engineering, not improvised.

Q · You need a login and you know it is security-sensitive. How do you derive the concept, its state and its operations without inventing the parts that must not be invented?
Case: Implement Inventory

Inventory is the available quantity of a product. Increase, decrease, reserve, release — then inject "stock = 1, Alice buys, Bob buys at the same moment" and watch the concept meet concurrency, and route the mechanism to Concurrency and Database.

Q · You need to track how many of each product are left. How do you derive inventory as a concept, and what happens to the derivation when two customers want the last unit at the same time?
Case: Implement Pagination

A hundred products fit on one page; ten thousand do not; ten million change the algorithm. Pagination derived from "show a slice of a list" — slice an array, then LIMIT / OFFSET, then a cursor — with the trigger for each level named.

Q · The product list is getting long and someone says "add pagination". What is pagination as a concept, and how do you know which of its three well-known mechanisms the current version justifies?
Case: Implement a Todo List

The simplest concept with identity: a todo has an id, a title and a done flag; the operations are add, toggle, remove, list. The first place a learner meets "one entry per id" — and the place to learn the whole loop on something small enough to hold in one hand.

Q · A todo list looks too simple to need a method. What does deriving it — instead of typing it — teach that you will need for every concept after it?
Case: Implement a Rate Limiter

N requests per window, per key. The state is a counter and a window start per key; the representation choice is fixed window against sliding window, and it changes what "N per window" means at the boundary. V2 is "shared across servers", and it changes where the state lives.

Q · You need to stop one client from sending too many requests. What is a rate limiter as a concept, what does it have to remember, and why does the choice of window change its behaviour rather than just its cost?
Case: Implement a Job Queue

Enqueue, dequeue, ack, retry. The state is a job with a status — pending, running, done, failed — and the rule that makes the queue honest: a job can run more than once, so its handler must be idempotent. Derived from "send the confirmation email later", as far as one process justifies.

Q · Something has to happen later, reliably, outside the request. What is a job queue as a concept, what state does each job carry, and why does "reliably" force a rule on code the queue does not own?