Live data from Hacker News

Write libraries instead of services, where possible

catern.com

141–150 of 328 posts

Re: Write libraries instead of services, where possible

#141
Phoenix is practically built with this idea in mind.

My startup is built out of a single phoenix monolith. Only external dependency is postgres.

Despite this, I've managed to completely avoid all the typical scaling issues of a monolith. Need a service or background worker? I juts make a Genserver or Oban worker and mount it in the supervision tree. The Beam takes care of maintaining the process, pubsub to said service and error handling in the event of a crash.

I'm basicly getting all the best advantages of a monolith

* one codebase to navigate, our team is TINY * all functionality is in libraries

And all the advantages of microservices without the associated costs. (orchestration, management etc)

* bottleneck use cases can live on their own nodes

* publish subscribe to dispatch background jobs

* services that each focus on doing one thing really well

We've accomplished this all through just libraries and a little bit of configuration. At no point so far have we had to..

* setup a message broker (phoenix pubsub has been fine for us. we can send messages between different processes on the server and to the clients themselves over channels)

* setup external clusters for background workers. (Oban was drop in and jsut works. I'm able to add a new worker without having to tell devops anything. the supervision tree allocates the memory for the process and takes care of fault tolerance for me. That leaves me to focus on solving the business problems)

* setup a second github repo. Its a monorepo and at out scale, its fine. We have one library for communicating to the database that every system just uses.

Eventually we'll probably have to start rethinking and building out separate services. But I'm happy that we're already able to get some of teh benefits of a microservice architecture while sticking to what makes monoliths great for mvps. It will be awhile before we need to think about scaling out web service. It just works. Leaves me more time to work on tuning out database to keep up!

Re: Write libraries instead of services, where possible

#142
After building embedded library codebases that have had version skew across clients (sometimes over several years worth of code), the library approach just stops evolving after a certain point - the backward compatibility mess is a drowning morass. There is no control on the upgrade cycle, old infra can't be turned down, performance is a risk, upgrades are a risk, every deploy has "foreign code" and the potential for a dependency mismatch. Services work - use them. Unless performance is of the utmost concern, say no to libraries.

Re: Write libraries instead of services, where possible

#143
post #38

Earlier quoted context omitted.

Communism doesn't work.

Of course it "works", there's been multiple countries run on it and continue to run on it. What you mean to say is you don't like it.

Just to head this off: Sweden isn't Communist or Socialist.

Re: Write libraries instead of services, where possible

#145
Clearly, it makes sense on the "sellers" side to make it into a service - the article pretty much conceded to that. However, this issue is also created by the "buyers" side as well. To give a concrete example - prometheus is an open source alternative for observability. But if you have a small team and want to release early, you will still go to DataDogs, and splunks of the world. Of course, you can say but that's fine. But there are others that could have been a library. Yes, but libraries also come with a maintenance overhead (security, patches, etc.).

Re: Write libraries instead of services, where possible

#146

Phoenix is practically built with this idea in mind. My startup is built out of a single phoenix monolith. Only external dependency is postgres. Despite this, I've managed to completely avoid all the typical scaling issues of a monolith. Need a service or background worker? I juts make a Genserver or Oban worker and mount it in the supervision tree. The Beam takes care of maintaining the process, pubsub to said servi…

BEAM will automatically distribute processes across a cluster, right?

Re: Write libraries instead of services, where possible

#148
post #2

I like the approach and it seems to be definitely better for everyone, but how you monetize a library?

It's easy, you release it open source... Then make sure you have languages "officially" promote it in their documentation and have people adopt it thinking it's great and an actively developed project that's going to be around forever, etc... And then fork it, stop releasing security updates for the older (open-source) versions, and turn it into a product that you charge people for because corporates are now dependent on it.

For a real-life example of it, see this blatant bait and switch fuckery: https://github.com/dotnet/aspnetcore/issues/26489

Re: Write libraries instead of services, where possible

#149

Phoenix is practically built with this idea in mind. My startup is built out of a single phoenix monolith. Only external dependency is postgres. Despite this, I've managed to completely avoid all the typical scaling issues of a monolith. Need a service or background worker? I juts make a Genserver or Oban worker and mount it in the supervision tree. The Beam takes care of maintaining the process, pubsub to said servi…

this sounds really neat and I'm going to go read about it!

I also wanted to call out that this ~sentence has just... a bunch of things that seem like jargon/names within the community? As an outsider, I have no idea what they mean:

> make a Genserver or Oban worker and mount it in the supervision tree. The Beam takes care of maintaining the process

it sounds very sci-fi :)

Post reply on HN