Daniel sent us this one — he's been thinking about pharmacies. The question is basically, how does your average retail pharmacy stock what looks like an impossibly vast number of medications, including obscure ones in different dosages, all in what looks like a filing cabinet behind the counter? He wants to know the actual numbers — how many different drugs and dosages does a typical pharmacy carry — and how they manage demand prediction and replenishment so they almost never run out. When failures happen they're painfully visible, but they happen so rarely the system must be doing something right.
Oh, this is one of those questions where the answer is genuinely more interesting than most people expect. The filing cabinet observation is the tell — the visible part is maybe five percent of the story. And I love that Daniel noticed this, because most people don't. They see the cabinet, they assume that's the pharmacy, and they move on with their day. But the cabinet is a stage set. It's the part of the iceberg above water.
The cabinet is a decoy.
Not a decoy, but a curated exhibit. Think of it like the books displayed face-out at a bookstore — those are the ones the store expects you to reach for. What you see from the counter is the fast-mover wall. The top two hundred or so drugs that account for the vast majority of prescriptions. Behind that wall, and I mean literally behind it in most pharmacies, there's a whole second pharmacy the patient never sees. Shelves and shelves of slower movers, refrigerated biologics, controlled substances in a separate locked safe that's bolted to the floor.
I'm now picturing a pharmacy as one of those restaurants where the dining room is charming and intimate, and then you walk through the kitchen doors and there's an aircraft hangar of prep stations and walk-in freezers.
That's exactly the right analogy. The front of house is designed to be approachable, calm, almost clinical in its tidiness. The back of house is industrial logistics. And the transition between them is usually a single door. Patients have no idea that six feet behind the pharmacist there's a shelving system that would look familiar to an Amazon warehouse manager.
What's the actual number? How many distinct drug-and-dosage combinations are we talking about?
A typical chain retail pharmacy — think CVS, Walgreens, Boots in the UK — carries somewhere between two thousand and four thousand distinct SKUs. And a SKU in pharmacy terms is one drug in one strength in one package size. So amoxicillin five hundred milligram capsules, count of thirty, that's one SKU. Same drug, same strength, count of ninety, that's a different SKU.
Four thousand things. That's more than I would have guessed, but also somehow less than the question implies. It sounds impossibly vast until you hear the number, and then you think — that's a medium sized grocery store's snack aisle.
And here's where it gets interesting. Of those four thousand SKUs, roughly two hundred drugs represent about eighty-five percent of all prescriptions dispensed. The top twenty alone — your atorvastatins, your lisinoprils, your metformins, your levothyroxines — those twenty drugs are something like thirty percent of all prescriptions filled in the United States.
It's a Pareto distribution on steroids. The top five percent of SKUs doing almost all the work.
The remaining three thousand eight hundred things are essentially insurance. They're there just in case.
The long tail is real but thin. The pharmacy stocks three thousand eight hundred things that each get dispensed maybe once a month.
And that's where the inventory management problem gets fascinating, because the economics of holding a box of some obscure anti-parasitic that expires in eighteen months, when you might dispense it twice a year, are terrible. But you have to stock it, because the patient who needs it is often the patient who really needs it.
The albendazole problem. Nobody thinks about albendazole until they have worms, and then they really think about albendazole.
The pharmacist's professional obligation — and in many jurisdictions, regulatory requirement — is to be able to fill that prescription within a reasonable timeframe. Usually same day or next day. So they hold inventory that would make a just-in-time logistics manager weep. A Toyota production engineer would walk into a pharmacy back room and have a panic attack.
I want to sit with that for a second, because it really is a wild constraint. In most retail contexts, if something is a slow mover, you stop carrying it. The craft store doesn't stock every color of embroidery floss from 1997. They cycle the inventory. But the pharmacy can't cycle the albendazole. They have to have it, or be able to get it within hours, because the alternative is telling someone with a parasitic infection to wait a week.
That's not just bad customer service. That's potentially a clinical failure. If a patient doesn't start that medication promptly, the consequences can be serious. So the pharmacy is operating under a completely different set of constraints than a normal retailer. The cost of a stockout isn't a lost sale of five dollars. It's a patient walking out without treatment.
How do they actually manage this? Is it all software at this point?
It is overwhelmingly software, yes, but the specific flavor of software matters. Pharmacy inventory management sits at this weird intersection of retail logistics and clinical supply chain. It's not just "reorder when low" — there are regulatory constraints, controlled substance tracking that gets reported to the DEA or equivalent agencies, cold chain requirements, recall management, expiration date management. And the demand patterns are spiky in ways that normal retail isn't.
A pharmacy doesn't just sell more allergy medication in spring — that part is predictable. What's less predictable is that a single local physician might switch their prescribing preference from one blood pressure medication to another, and suddenly your carefully calibrated par levels for the old drug are all wrong. Or a new clinical guideline drops — the American Heart Association updates something — and within a week, prescribing patterns shift across the entire country.
You're not just forecasting demand, you're forecasting physician behavior.
Which is downstream of journal publications, conference presentations, insurance formulary changes, and drug rep activity. It's a bizarrely complex signal chain. The major pharmacy chains have entire data science teams dedicated to this. Walgreens, for instance, uses a system called SIMS — Strategic Inventory Management System — that does automated replenishment across their entire network. CVS has their own equivalent. These systems are ingesting prescription data in near real time and adjusting order points dynamically.
Are we talking actual AI, or is this more like sophisticated statistical modeling with an AI label slapped on?
The core of most of these systems is still time-series forecasting — ARIMA models, exponential smoothing, that kind of thing — but layered on top of that are machine learning models that handle the weird edge cases. Things like detecting when a particular prescriber's pattern has shifted, or identifying that a specific pharmacy location has an unusual demographic mix that doesn't match the chain average.
Give me an example of the demographic thing.
A pharmacy near a retirement community will have dramatically different prescribing patterns than one near a university. That's obvious. But a pharmacy near a retirement community that's also near a pediatrician's office — now you've got a bimodal demand distribution that standard forecasting models struggle with. You're simultaneously stocking large quantities of geriatric cardiac medications and pediatric antibiotic suspensions. A simple average doesn't capture either population well. The machine learning systems can pick up on those patterns and adjust accordingly.
The computer is basically saying, "this location dispenses an unusual amount of both cholesterol medication and amoxicillin suspension, and we need to stock accordingly.
And the systems get increasingly sophisticated. Some of the larger chains are now incorporating weather data, local event calendars, even flu trend data from sources like Google's now-defunct Flu Trends or its modern equivalents, to anticipate demand spikes. A pharmacy near a major airport might see different patterns during holiday travel seasons. A pharmacy in a college town sees a spike in certain prescriptions during exam periods.
Exam period prescriptions. That's a sad little data point.
Stimulants, anti-anxiety medications, sleep aids. It's a well-documented phenomenon. But from an inventory management perspective, it's another signal the system has to incorporate. And this raises an interesting question about how far you can push that kind of predictive modeling before it starts feeling invasive. The pharmacy knows, in aggregate, that exam season means more prescriptions for certain categories. But the system isn't predicting individual behavior — it's predicting population-level demand. The ethical line is actually fairly clear, even if it feels uncomfortable.
I suppose the alternative is the pharmacy being out of stock during exam season, which helps no one. But I take your point — there's a version of this that starts to feel like the system knows too much about a community's rhythms.
The pharmacy chains are generally careful about this, partly for regulatory reasons and partly because the reputational risk of being seen as exploiting that data is significant. But the capability exists. The data is there.
Let me ask about the failure mode. I go to the pharmacy, they don't have my prescription. How often does this actually happen, and what breaks when it does?
The industry benchmark for in-stock rates at retail pharmacies is around ninety-seven to ninety-nine percent for common medications. For specialty drugs, it drops — maybe ninety to ninety-five percent depending on the chain and the drug category. So the system fails visibly maybe one to three times per hundred prescriptions.
That's actually higher than I would have guessed from the prompt's framing. Daniel made it sound like these failures are vanishingly rare.
There's a distinction between "we don't have it and can't get it" versus "we don't have it right now but can have it by this afternoon." Most of the time when a pharmacy doesn't have something, it's a same-day replenishment issue. The major chains get daily deliveries, sometimes twice daily in high-volume locations. So the out-of-stock that the patient experiences is often just timing — they showed up before the delivery truck.
Which is still a failure from the patient's perspective. They made the trip. They're standing at the counter. They don't have their medication.
And it's a failure that pharmacy chains take extremely seriously, because in most markets, the patient can just walk across the street to a competitor. Pharmacy loyalty is surprisingly thin. If you fail to fill a prescription twice, the patient switches, and they might never come back. There's research on this — pharmacy customers have some of the lowest switching costs of any retail category. You don't need to set up a new account, you don't need to learn a new store layout, you just hand the prescription to a different pharmacist.
The stakes for the inventory system are actually enormous. A stockout isn't just a missed transaction — it's potentially a lost customer for life.
In a business with two to three percent margins, you can't afford to lose many customers for life.
What actually causes the stockout? Is it a forecasting error? A supply chain disruption? Someone just forgot to order?
The most common causes, in rough order: manufacturer backorder — that's the big one, and it's upstream of the pharmacy's own inventory system. A drug goes on backorder nationally and no amount of local forecasting helps. Second is what's called a "demand spike at the tail" — one of those obscure drugs suddenly gets prescribed three times in a week when normally it's prescribed three times a year. The forecasting model didn't see it coming because there wasn't enough historical data to build a pattern.
The albendazole problem again.
The albendazole problem. Third is wholesaler issues — the pharmacy's supplier has a distribution center problem, a picking error, whatever. And fourth is human error at the pharmacy level. Someone didn't confirm the order, or a return wasn't processed correctly and the system thinks there's inventory that isn't actually there.
That last one feels like it should be solvable. RFID tags on everything, automated inventory counting.
It is solvable, and some hospital pharmacies do exactly that — RFID-tagged inventory with automated tracking. In a hospital setting, the economics work because the cost of a stockout can be measured in patient harm, and the inventory is higher value on average. But in retail, the economics don't work yet. The margins on pharmacy dispensing are thin enough that adding RFID tags to every bottle would wipe out profitability on a significant portion of the formulary. You'd be spending maybe twenty to fifty cents per tag on a prescription that might only generate a couple of dollars in gross profit.
Wait, back up. Pharmacy margins are thin?
The average independent pharmacy operates on a net profit margin of maybe two to three percent. Chains do better through scale and vertical integration — CVS owning Caremark, their pharmacy benefit manager, gives them negotiating leverage — but even then, the dispensing business itself is not where the money is made. The money is in the front of store. The pharmacy exists to bring people in.
The entire pharmaceutical edifice — the inventory management systems, the data science teams, the regulatory compliance, the controlled substance safes bolted to the floor — all of it is a loss leader for greeting cards and seasonal candy.
Cosmetics are huge. The pharmacy is the anchor tenant of the drugstore, not the profit center. This is why independent pharmacies have been getting crushed for decades. They don't have the front-of-store revenue to subsidize the pharmacy operations. An independent pharmacy is just a pharmacy, and a pharmacy alone is a very difficult business to make work.
That's a non-obvious structural fact about how the whole system works. The thing I think of as "the pharmacy" is actually a very elaborate customer acquisition funnel for moisturizer.
It's the retail equivalent of a gas station. Gas stations don't make money on gas. They make money on the convenience store attached to the gas station. The gas is there to get you to stop.
I'm now picturing a pharmacy with rotating hot dogs.
Some of them basically have that. The CVS near me has an entire refrigerated prepared foods section now. Sushi, sandwiches, the works.
The circle of retail life. Everything eventually becomes a convenience store.
Everything eventually converges on selling the same five categories of high-margin goods. But to bring it back to the inventory question — this structural fact actually explains something important about how pharmacies manage their stock. Because the pharmacy exists to drive traffic, the tolerance for stockouts is even lower than it would be in a pure profit-center business. If a grocery store is out of a particular brand of pasta, you buy a different brand. If a pharmacy is out of your specific blood pressure medication, you can't substitute. You need that exact drug in that exact dosage. So the inventory system has to be extraordinarily reliable, even though it's supporting what is essentially a break-even operation.
Which is why the visible filing cabinet is so misleading. The patient sees a modest storage system and thinks "that can't possibly hold everything." And they're right — it doesn't. The visible cabinet is just the tip of the iceberg, and the iceberg itself is being sustained by an elaborate computational apparatus that exists to sell you lipstick.
The computational apparatus is impressive. Let me walk through what actually happens when a prescription comes in, because it illustrates how the forecasting works in practice. Patient drops off a prescription for, say, atorvastatin forty milligrams. The pharmacy's system checks inventory — they have it, they dispense it. That transaction immediately decrements the inventory count and feeds into the demand forecasting model.
Real-time demand sensing.
But here's the clever part. The system isn't just tracking that one transaction. It's tracking that this is the third atorvastatin forty milligram prescription filled this afternoon, which is slightly above the Tuesday afternoon average. And it's checking whether this is part of a broader pattern — are all statins up? Is it just this strength? Is it just this prescriber? Martinez just switched her preferred statin therapy and now all her patients are showing up with atorvastatin scripts. The system needs to figure out whether this is a permanent shift or just noise.
It's doing this across thousands of pharmacies simultaneously.
Tens of thousands. Walgreens alone has about nine thousand locations in the US. Each one generating transaction data continuously. The central system is looking for patterns at the individual pharmacy level, the regional level, and the national level simultaneously. It's a massive data processing challenge.
When you say "the computer orders the drugs," what does that actually look like? Is there a human checking the computer's work?
It depends on the chain and the drug category. For fast movers — the top two hundred or so — the system typically auto-generates purchase orders that go directly to the wholesaler with minimal human intervention. The pharmacy manager might review a summary report in the morning, but they're not hand-approving each reorder. For controlled substances, there's always a human in the loop — partly for regulatory reasons, partly for diversion prevention. And for very expensive specialty drugs — the ones that cost thousands per dose — there's usually manual review because the carrying cost of being wrong is so high. You don't want an algorithm accidentally ordering an extra three units of a drug that costs eight thousand dollars per vial.
What about the expiration date problem? Four thousand SKUs, many of them sitting on shelves for months between dispensings. How do they not end up throwing away half their inventory?
This is one of the elegant parts of the system. Most pharmacy inventory software does expiration date tracking at the lot level. When a shipment comes in, the pharmacy staff scans the lot number and expiration date into the system. The software then prioritizes dispensing the soonest-to-expire stock. And when something is approaching expiration — typically within three to six months — the system flags it for return to the wholesaler.
The wholesaler takes it back?
Often yes, especially for brand-name drugs. It's part of the contractual arrangement. The wholesaler can redistribute it to a higher-volume pharmacy that will dispense it before expiration, or they have their own reverse logistics system for handling short-dated product. For generics, which are cheaper, it's sometimes more economical to just dispose of them. But the system is designed to minimize that. And I should add — this isn't just good business practice. There are regulatory requirements around expiration date management. Dispensing expired medication is a serious violation. So the tracking has teeth.
The pharmacy is essentially running a just-in-time inventory system for most things, with a safety stock buffer for the long tail, and a returns pipeline that functions as a release valve for the expiration problem.
And the safety stock calculation is where a lot of the statistical sophistication lives. How much buffer do you hold for a drug that you dispense on average once every six weeks? Too much and you're wasting capital and shelf space and risking expiration. Too little and you stock out when that one patient shows up.
What's the actual math? How do they calculate the right buffer?
The classic approach is something called the newsvendor model — it's an operations research framework that balances the cost of holding too much inventory against the cost of holding too little. The name comes from the newspaper vendor who has to decide how many papers to buy in the morning, knowing that unsold papers are worthless at the end of the day and lost sales represent missed profit. You're optimizing against two different kinds of error. But for pharmacy, the cost of holding too little isn't just financial — there's a clinical dimension. So the safety stock levels are typically set higher than a pure economic model would suggest. Some chains use what's called a service-level target — they'll say "we want to be able to fill ninety-nine percent of prescriptions immediately from stock," and the system calculates the inventory levels required to hit that target given the historical demand variability.
For the really obscure stuff?
For the very long tail, the strategy often shifts from "stock it" to "source it fast." Most retail pharmacies have relationships with multiple wholesalers, and they can often get a non-stocked drug delivered within four to twenty-four hours. Some chains also use a hub-and-spoke model where one pharmacy in a region stocks the really obscure drugs and the others can pull from it as needed. So the regional hub might carry the albendazole, and when a patient shows up at a satellite location needing it, the system routes it over.
When I show up with a prescription for some exotic medication and the pharmacist says "we can have it by tomorrow morning," what's actually happening is a courier is bringing it from a regional hub, or from a wholesaler's local distribution center.
Or in some cases, from another pharmacy in the same chain that's fifteen minutes away. The patient never sees this coordination layer. They just know it arrives. There's an entire parallel logistics network dedicated to moving individual prescriptions between locations, and it runs quietly in the background. I find it impressive.
Which brings us back to the original observation — the system works so well, so consistently, that it's basically invisible. The only time anyone thinks about pharmacy inventory management is when it fails.
Even then, most people think "the pharmacy is out of my medication" rather than "a complex sociotechnical system involving demand forecasting algorithms, multi-echelon inventory optimization, wholesaler logistics networks, and regulatory compliance frameworks experienced a transient local failure.
The sociotechnical system doesn't fit on the "we apologize for the inconvenience" sign.
It does not. Though I would love to see a pharmacy try. "We regret that our multi-echelon inventory optimization model failed to anticipate your specific demand signal. A courier is en route from our regional hub.
I would respect that pharmacy enormously.
You might be the only one. Most people just want their lisinopril.
Let me ask about the independent pharmacies. You mentioned they're getting crushed. Are they using the same kinds of systems, or are they running this on spreadsheets and intuition?
It's a mix. The pharmacy management software market has consolidated a lot — there are maybe half a dozen major vendors, and even independent pharmacies are typically running one of them. So they have access to automated reordering and basic demand forecasting. But they don't have the data science teams, they don't have the hub-and-spoke networks, and they don't have the negotiating leverage with wholesalers. An independent pharmacy is buying at a different price point than CVS, and they're doing it with a fraction of the analytical firepower.
Their in-stock rates are worse?
Often yes, though there's a countervailing factor. Independent pharmacists tend to know their patient base more intimately. A good independent pharmacist knows that Mrs. Chen needs her brand-name thyroid medication — not the generic, because she doesn't tolerate the generic well — and she'll be coming in on the third Thursday of the month. That kind of tacit knowledge can substitute for some of the algorithmic sophistication. It's a different kind of intelligence. The chain has scale and data. The independent has relationships and memory.
Human inventory management. The original AI.
The original intelligence, no artificial required. But it doesn't scale, and it doesn't survive the pharmacist retiring or selling the business. The chains have institutional knowledge embedded in their systems. The independents have it in their heads. When the independent pharmacist retires, all that tacit knowledge walks out the door. When a chain pharmacist leaves, the system doesn't even notice.
That's actually a little melancholy. Decades of knowing exactly what Mrs. Chen needs, and then it's just gone.
It's the tradeoff of systematization. You gain reliability and scalability, but you lose something human in the process. Though I should note — Mrs. Chen probably gets better inventory reliability from the chain in the long run. The algorithm won't forget she's coming. It just won't know her name.
How much of this whole edifice is actually regulated? Is the government telling pharmacies what they have to stock?
Not directly, no. There's no federal law in the US that says "a pharmacy must stock these specific drugs." But there are professional standards and state-level regulations that effectively require a pharmacy to maintain a reasonable inventory. The phrase "reasonable inventory" is deliberately vague, but it's interpreted to mean that a pharmacy should be able to fill most prescriptions without undue delay. And for controlled substances, there are detailed record-keeping requirements that effectively mandate sophisticated inventory tracking.
The DEA cares a lot about the oxycodone inventory but not at all about the amoxicillin inventory.
The controlled substance inventory management is an entirely separate system layered on top of the regular inventory system. Every single pill has to be accounted for, from manufacturer to wholesaler to pharmacy to patient. Discrepancies get investigated. It's a level of granularity that would be absurd for most products but makes sense given the abuse potential. If two oxycodone tablets are unaccounted for, that's not a rounding error — that's an investigation.
That's all digital now?
There's been a push toward what's called e-prescribing for controlled substances — EPCS — which creates a fully digital audit trail from the prescriber's electronic health record through to the pharmacy dispensing system. It's not universal yet, but it's heading that way. The paper prescription for controlled substances is slowly going extinct, and good riddance — paper prescriptions were a major vector for fraud and diversion.
The pharmacist is sitting at the center of multiple overlapping information systems — the retail inventory system, the controlled substance tracking system, the insurance adjudication system, the prescriber communication system — and also somehow finding time to counsel patients and count pills.
This is why pharmacy burnout is a real problem. The cognitive load is enormous. But the inventory part, at least, has been automated to the point where it's not the main source of stress. The system works. The pharmacist's daily inventory management is mostly exception handling — dealing with the one weird case the algorithms couldn't handle. The computer handles the routine. The human handles the anomalies.
Which brings us to AI. You mentioned machine learning for demand forecasting. Are we at the point where the entire system could run autonomously?
Technically, for the non-controlled substances, probably yes. The technology exists to fully automate the inventory management piece. But there are reasons it hasn't happened completely. One is regulatory — many states require a pharmacist to be involved in procurement decisions. Another is liability — if an algorithm makes a bad call and a patient can't get their medication, who's responsible?
The algorithm's not going to testify at a board of pharmacy hearing.
And there's a deeper issue, which is that pharmacy inventory management isn't a closed system. It's affected by drug shortages, manufacturer recalls, natural disasters, pandemics — exogenous shocks that no forecasting model can fully anticipate. During the early COVID period, pharmacy inventory systems went haywire because demand patterns shifted so dramatically and so quickly. Hydroxychloroquine demand spiked by something like two thousand percent in a matter of weeks.
Based on, as it turned out, not much evidence.
Right, but the inventory system doesn't know that. It just sees demand. And that's the fundamental limitation of any forecasting system — it's extrapolating from historical patterns, and when the world changes discontinuously, the extrapolation fails. The pharmacist's judgment is still the backstop. When hydroxychloroquine demand went through the roof, pharmacists had to make calls — do we limit dispensing? Do we prioritize certain patients? Those are ethical judgments, not algorithmic ones. The computer can tell you demand is spiking. It can't tell you what to do about it.
The filing cabinet behind the counter is a monument to a largely invisible system that works almost perfectly almost all of the time, except when the world breaks.
Even when it breaks, it usually recovers within twenty-four hours. The resilience is built into the supply chain at multiple levels — safety stock at the pharmacy, backup inventory at the wholesaler, alternative suppliers, inter-pharmacy transfers. It's one of the more impressive logistics achievements in the modern economy, and almost nobody thinks about it.
Until they're standing at the counter being told their medication isn't ready.
Then they think about it very intensely for about five minutes, and then they forget about it again.
The attention span of the aggrieved consumer.
It's the attention span of anyone who's been trained by a system that works so reliably that failure feels like a personal affront rather than a statistical inevitability. We've built infrastructure so dependable that we've forgotten it's infrastructure. We experience it as a natural feature of the landscape, like gravity. And when gravity briefly fails, we're outraged.
There's something almost beautiful about that. A system so optimized, so layered with redundancy and intelligence and care, that its success is measured by its invisibility. Nobody writes Yelp reviews saying "pharmacy had my medication in stock, as expected.
The Yelp review problem. The only feedback is failure. Every system that works perfectly is a system nobody talks about.
The glockenspiel of corporate approachability, but for logistics.
There's a phrase I didn't expect to hear today. But yes, the entire pharmacy inventory apparatus is basically build me a chair nobody notices they're sitting in. And they built it. Four thousand SKUs, managed in real time, distributed across tens of thousands of locations, with a ninety-seven-plus percent in-stock rate, all to sell you moisturizer.
The moisturizer is the point. Never forget the moisturizer.
Never forget the moisturizer. It's the philosophical core of the entire enterprise.
Now: Hilbert's daily fun fact.
Hilbert: In the 1810s, British geologist Thomas Hardwicke proposed that the diatomaceous earth deposits of Bhutan's high valleys were the fossilized remains of an ancient inland sea that once connected the Himalayas to the Bay of Bengal. The theory was mainstream for nearly thirty years before it was abandoned when chemical analysis revealed the deposits were freshwater diatomite formed in glacial lakes, not marine sediment. Hardwicke had the right fossils but the wrong water. The diatoms were real. The sea was not.
Hardwicke's Himalayan sea. A perfectly reasonable theory that turned out to be a lake.
Most things do.
This has been My Weird Prompts. Thanks to our producer Hilbert Flumingtop. If you enjoyed this episode, leave us a review wherever you listen — it helps people find the show. We'll be back next week with whatever Daniel throws at us.