Skip to main content

Ralsina.Me — Roberto Alsina's website

Coffee As a Service Architecture

Coffee As A Service Architecture


To­day I was in a meet­ing with re­cruiters (yes, re­al­ly) be­cause they want to be bet­ter at tech­ni­cal re­cruit­ing and they had the idea that talk­ing to me would help them (o­h, sweet sum­mer chil­dren).

A nice time was had by all (I hope) and at one point I was asked about what ar­chi­tec­ture was, and more specif­i­cal­ly, about the dif­fer­ence be­tween mi­croser­vices and a mono­lith.

Which I tried to ex­plain us­ing what I had at hand: cof­fee cup­s, sug­ar dis­penser­s, a spoon and so on. It did­n't quite work out but I kept think­ing about it on my way home and ... let's try again.

What is Architecture?

Ar­chi­tec­ture, when it comes to soft­ware, can be de­fined in many ways, but one way I like is to say that ar­chi­tec­ture in­volves:

  • What the com­po­nents of your sys­tem are
  • How they are done
  • How they talk to each oth­er

There is a lot more, but you start with that, and that is more or less enough to ex­plain mono­liths and mi­croser­vices.

The Coffee Service

One thing of mas­sive im­por­tance about sys­tems is that they are meant to do some­thing. They ex­ist for a pur­pose. So, let's sup­pose the pur­pose of our sys­tem is to make cof­fee and put it in a cup.

We can call the cup the "cof­fee clien­t" and what­ev­er we use to make the cof­fee is the "cof­fee sys­tem" or "cof­fee ser­vice"

So, as­sum­ing you have a can full of cofee beans and a cup, how do you make cof­fee?

The Coffee Monolith

This is my very own cof­fee ma­chine. Not on­ly is it mono­lith-shaped, it's func­tion­al­ly mono­lith­ic (it's al­so large enough to de­serve its own table, as you can see).

It has two buck­ets on top. On one you put wa­ter, in the oth­er you put cof­fee bean­s. Then, you put a cup un­der the spig­ot and press a but­ton or two.

It will:

  • Grind the beans
  • Put the ground cof­fee in the right place and ap­ply the "right" pres­sure
  • Heat the wa­ter to the "right" tem­per­a­ture
  • Run wa­ter through the cof­fee grounds
  • Pour the cof­fee in­to the cup
  • Dis­card the grounds in­to a hid­den de­posit

Sounds awe­some, right? It is!

It takes all of 30 sec­onds to go from cof­fee beans to a nice cup of cof­fee! It tastes good!

And it's im­por­tant to keep that in mind. IT IS GREAT.

Mono­lith­s, when they done cor­rect­ly and you are not ex­pect­ing any­thing out of their op­er­at­ing pa­ram­e­ter­s, are awe­some.

The prob­lem with mono­liths is not that they can't be done right, it's that it's hard to do them right, and that even when you do get it right, in our in­dus­try the mean­ing of "right" is not fixed.

So, be­cause the whole point is to ride this anal­o­gy in­to the ground, let's con­sid­er all the things about this awe­some ma­chine.


It grounds the cof­fee. What hap­pens if you want it ground fin­er? Or coarser?

It turns out that if you have the right tool you can ad­just the mil­l's out­put (it's not in the man­u­al).

In a mi­croser­vice-based cof­fe­mak­er I would re­place the grinder.

How about wa­ter tem­per­a­ture?

It has three set­tings. Want any­thing else? No luck.

In a mi­croser­vice-based cof­fee ser­vice I would just use an ad­justable ket­tle.

How about the amount of cof­fee per cup?

It has three set­tings. Want any­thing else? No luck.

In mi­croser­vice-­cofee I would just trans­mit as much cof­fee as I want­ed.

How about chang­ing the bean va­ri­ety be­tween cup­s?

The bean hop­per takes half a pound of bean­s. It's not easy to get them out. So, no.

In mi­croser­vice-­cof­fee heav­en I could have mul­ti­ple hop­pers pro­vid­ing beans of all va­ri­eties and just con­nect to the one I want to­day!

Cup size?

It does two sizes (but you re­pro­gram those sizes)

In mi­croser­vice-­cofee I would just pour as much wa­ter as I liked.

A mono­lith has the flex­i­bil­i­ty its de­sign­ers thought of adding, no more, no less. And chang­ing it is ... not triv­ial.

I could use a vac­u­um clean­er to re­move the beans from the hop­per and change va­ri­eties. I would con­sid­er that a hack. I have al­so done it. I re­gret noth­ing.

Unused Features

It has a thing that lets you set­up a cred­it sys­tem for cof­fee cups I will nev­er use. A milk foamer I use once a week. Why? Be­cause "we may need this and it's hard to add it lat­er, so let's just do it from the be­gin­ning" ground cof­fee.

Some­times yes, it's use­ful (ca­puc­ci­no!) but some­times it's just some­thing I paid for and will nev­er use (cof­fee cred­it­s!)

In a mi­croser­vice ar­chi­tec­ture I would just get a new milk foamer, use both for a while and then keep us­ing the one I like.

Hard to Improve

How do I add a bet­ter foam­ing thingie?

By buy­ing one and putting it in the ta­ble.

How do I add a more flex­i­ble cof­fee grinder?

I can't be­cause this ma­chine is in­com­pat­i­ble with pre-­ground cof­fee. There is a new­er, more ex­pen­sive mod­el that can take that but this one? You need to throw it away.

Mod­i­fy­ing a mono­lith­ic sys­tem is dif­fi­cult be­cause the pieces are tight­ly cou­pled. I can't use a sep­a­rate grinder be­cause the sys­tem re­quires the cof­fee grounds to ar­rive via a spe­cif­ic in­ter­nal duct at a spe­cif­ic point in the cof­fee-­mak­ing cy­cle, there is just no way to in­sert my grind-o-­mat­ic-3000 in there with­out a saw and duct tape.

In a mod­u­lar sys­tem I would un­plug the grinder and in­sert a com­pat­i­ble-but-d­if­fer­ent grinder, in a mi­croser­vice ar­chi­tec­ture I would just use what­ev­er grinder and put the cof­fee grounds in a mes­sage and have the next piece in the sys­tem pick it from there.


This cof­fee ma­chine is ex­pen­sive. It's much more ex­pen­sive than buy­ing a grinder, a cof­fee ma­chine a ket­tle and a milk foamer.

What it pro­vides in ex­change for the ex­tra mon­ey (and re­duced flex­i­bil­i­ty and so on) is per­for­mance. I don't boil wa­ter, I don't grind cof­fee, I don't pour, I just press a damned but­ton and en­joy cof­fee.


You can buy pre-­ground cof­fee and ef­fec­tive­ly out­source that part of the process to some ex­ter­nal provider.

I can't! I am doomed to ground my own cof­fee for­ev­er.


I have a lu­bri­ca­tion sched­ule, or else my ex­pen­sive ma­chine will break.

I have to dis­in­fect the cof­fee ground bin or else it will have mag­got­s.

I have to emp­ty the wa­ter waste tray be­fore it over­flows.

I have to have a thing to dump the bits of dirty wa­ter it us­es to clean it­self when it turns on/of­f.

I have to buy spe­cial acid to pe­ri­od­i­cal­ly re­move scale from its in­nards or it will stop work­ing. That costs ac­tu­al mon­ey and takes half an hour.

I need to cleanup cof­fee crud from all the in­ter­nal springs, levers and thin­gies ev­ery cou­ple of week­s.

Now, you, read­ers with nor­mal cof­fee mak­ing things? How is your cof­fee ma­chine main­te­nance rou­tine? What, you don't have one? Thought so.


So, that's why nowa­days most peo­ple pre­fer to pay the per­for­mance penal­ty of a mi­croser­vice ar­chi­tec­ture in­stead of us­ing an awe­some mono­lith.

This is not ex­haus­tive, there is still sep­a­ra­tion of con­cern­s, en­cap­su­la­tion, rigid­i­ty of con­tracts and a lot more, but it should be con­vinc­ing enough with­out be­ing dog­mat­ic :-)

Contents © 2000-2023 Roberto Alsina