For decades, becoming a pharmacist and running your own drugstore yielded a good living and a rewarding sense of service to others.

Over the last decade, however, Minnesota has lost more independent pharmacies than any other state.

This problem is emblematic of an industry that has tilted too far in the direction of scale and efficiency as drugstore chains gobble up market share. It's been exacerbated by the rise of middlemen known as pharmacy benefit managers, or PBMs.

A century ago, drugstores sprouted up in every town of more than a thousand people and in most neighborhoods of Minneapolis and St. Paul.

Operating an independent pharmacy has become more financially difficult, said Deborah Keaveny, who co-owns Keaveny Drug in Winsted, about an hour west of the Twin Cities.

"Pharmacy used to be a noble business. We were never rich, but we were OK," Keaveny said. "Now, a lot of us have mortgaged our houses. We've cut our own wages. We have reduced staff as much as we possibly can. If you've got an independent pharmacy that's still around, man, they have been through the wringer."

Drug delivery has become enormously complex, with numerous intermediaries and convoluted pricing models. On Tuesday, CVS Health, the nation's No. 2 drugstore chain, said it would abandon complex price schemes for a simple mark-up on wholesale costs.

Independent pharmacies provide a measure of resilience and flexibility in the industry. They're often the only option in small communities.

"I know I'll never buy drugs," Keaveny said, referring to working directly with drugmakers as the big chains and wholesalers do. "But I will kill them on service every single day."

Dispensing prescriptions, indeed, is now done mainly by hospital systems, national drugstore chains and e-commerce firms — three groups of businesses that weren't around in 1980.

One place is an exception. North Dakota requires that pharmacies be owned by pharmacists. A 1963 law, originally devised to draw lines between the work of doctors and pharmacies, wound up keeping drugstore chains out of the state. Some North Dakotans complain about the lack of competition, but drug prices there are lower than in most states, including Minnesota.

The demise of independent pharmacies in Minnesota and many other places is being hastened by another group of businesses — the PBMs.

Spawned in the 1960s, PBMs started growing large in the 1990s. They've consolidated with four companies, including Eagan-based Prime Therapeutics and the OptumRx unit of Minnetonka-based UnitedHealth Group, now controlling 68% of the market.

PBMs negotiate drug prices on behalf of big insurers and their clients, including large corporate and government employers. At first, they helped independent pharmacies by bringing negotiating power with drugmakers that the mom-and-pop businesses could never dream of having.

Eventually, they set contract terms that let them control pricing and steer patients to pharmacies in their networks. Sometimes, that put drugstores in no-win positions.

"There were cases where we brought in new customers and it was actually bad for us because we lost money filling their prescriptions," said Deborah Leedahl, who closed Kemper Drug in Elk River earlier this year after a clash with a PBM.

Leedahl, who has been a pharmacist for 19 years, bought Kemper Drug in 2017, fulfilling a goal she'd had since pharmacy school. It fell apart when just one of the PBMs, amid a dispute with Leedahl over the handling of a single payment, removed the store from its network.

"That was a large chunk of our customers. ... We weren't profitable up to that point. We could just stop and be better off," Leedahl said. "If the PBMs hadn't been paying us so poorly, it would have been a different scenario."

Elk River had a Walgreens and Leedahl transferred her customer list to it. Some other Minnesota towns have become pharmacy deserts when their independent business folded.

This year, 24 pharmacies have closed in Minnesota, according to the Minnesota Pharmacists Association. Six were part of national chains, one was in the regional chain Thrifty White and the rest were independents. There are 126 independent pharmacies left in the state.

A bill that might have helped independent pharmacies got stymied in the Minnesota Legislature this spring because of a complication involving price discounts called 340B contracts.

Last Friday, Rep. Tina Liebling, DFL-Rochester, presided over a hearing that examined 340B contract usage in Minnesota. The Legislature this spring proposed assuring a profit to pharmacies serving the state's Medical Assistance program, which covers about one-fifth of Minnesotans.

The way that bill was structured, however, cut off pharmacies and hospitals from the 340B discount. They protested. "It had some ramifications that got out of control," Liebling said.

Whether on the state or federal level, some restrictions on PBMs seem inevitable. The Federal Trade Commission is examining key practices of PBMs, including the clawback of overpayments to pharmacies.

OptumRx has halted some of its clawbacks already, executives say. The company has announced other steps to assist independent pharmacies. "We're pro-independent pharmacies and are in the market with solutions," an executive told me recently.

In January, drugstore owners face a clawback cliff. Collections of overpayments that were retroactive are changing to be forward-looking. That means pharmacies may have to return twice as much money as usual to PBMs. Keaveny said independent pharmacists have been putting cash aside or lining up special loans to get through the moment.