COFFEE was once Kenya’s biggest foreign-exchange earner, but these days the industry looks less perky. The country’s record, 127,000-tonne crop was all the way back in the 1987-88 season. Output plunged by 40% the following year, after the global coffee cartel axed its quotas, exposing the industry to competition. It has been falling ever since: last year it was less than 45,000 tonnes, a mere 0.5% of coffee production worldwide.

That is not for lack of quality. Kenya’s arabica coffee, grown in the highlands around Mount Kenya, is world-renowned, unlike the robusta produced in places like Vietnam and Brazil and used in instant granules. Domestic consumption is tiny, but growing by as much as 20% a year, as coffee-shop chains expand to cater to Kenya’s growing middle class.

That middle class also craves better housing, however, generating an insatiable thirst for land among developers. Nairobi’s property market is bubbling. The road between the capital and Thika, a town on the brink of being swallowed by its northern suburbs, is lined with coffee plantations that have been sold to developers. No one has bothered to pull up the weeds overtaking the coffee bushes on one hill-top outside Thika that is destined to become 500 homes.

For many smallholders, who account for 60% of the country’s coffee production, there just isn’t enough money in beans anymore. Some small farmers have abandoned the crop altogether for vegetables or other, more lucrative export crops, such as macadamia nuts. It doesn’t have to be this way. Coffee production in neighbouring Uganda has more than doubled since 1990, to 285,000 tonnes. In 2010, the most recent year for which comparative data are available, Kenyan coffee farmers received 20% of the export price of their crop, compared with more than 80% in Uganda.

Mismanagement has played a part in the Kenyan industry’s decline. The Kenya Planters Co-operative Union (KPCU), which owned 70% of the country’s milling capacity at its peak as well as providing its smallholder members with loans and cheap fertiliser, went bust in 2009. It came out of receivership in 2014, but allegations about its past were aired last autumn and led some farmers to threaten to leave their harvests on the bushes in protest. These included stories of a boardroom fistfight over the purchase of new computers, and of the theft of all the machinery from the KPCU’s Nairobi mill, as well as unconfirmed reports that some of the organisation’s directors had looted loans and coffee-sale proceeds meant for its members for nearly two decades before it went under.

Regulation has left the industry with a Byzantine structure that presents many opportunities for skimming off money. Only 10% of beans are bought directly from farmers. Most smallholders belong to a co-operative, which skins, ferments and dries the coffee beans before passing them on to a miller that finishes the processing and grading. The bags then go to one of eight licensed marketing agents, which sell the coffee to 60 local and international dealers at the Nairobi Coffee Exchange.

The exchange’s auctions, which take place in the bowels of a half-empty building in a rundown area of the city, had to introduce a $1,500 dealer registration fee after marketing agents withheld coffee in 2012 in protest at buyers that existed solely to resell the free coffee samples to which they were entitled. Disgruntled participants claim that “cartels” rig the bidding, suppressing prices. One Kenyan journalist claims to have witnessed dealers whistling to each other as a signal to hold down prices. The only noises your correspondent heard in the dimly-lit room, which resembles a 1960s lecture theatre, were hushed murmurs and bleeps as traders pressed buttons to place bids, and polite applause when one lot of coffee sold at a record price for the season.

Nonetheless, many of the mills, marketing agents and dealers are sister companies, which probably reduces competition to buy the wares of farmers. The multi-layered system has been further complicated by the decision of some local governments to set up their own mills and marketing agents. Further government meddling of this sort, needless to say, is unlikely to solve the industry’s problems.

In Uganda, in contrast, the industry has been completely liberalised since 1992. There are no auctions: middlemen compete vigorously to buy directly from farmers and sell on to exporters. If Kenya’s government wants to make good on its promise to double coffee production by 2020, it should wake up to the smell of its neighbour’s success.