Live data from Hacker News

Write libraries instead of services, where possible

catern.com

151–160 of 181 posts

Re: Write libraries instead of services, where possible

#151
post #72

Earlier quoted context omitted.

The idea is to link a thin client library into the user’s code. Then the thick client is controlled server side by the devs. If you design the thin and thick client intelligently, you can make a lot of changes to the system by merely modifying the thick client (which you control), without needing to update the thin client. Problems tends to come in a few flavors, namely that this increases complexity and that some ch…

I don't quite understand what you are saying. As per the article, the advantage of a library over a service is that you don't have the burden of maintaining the said service. How having a thin client and a server helps? I also don't see how "shoving new options in the dict" can help. From my POV, if the client needs to be updated to benefit from the new features, then there is no way around it, work has to be done. F…

> From my POV, if the client needs to be updated to benefit from the new features, then there is no way around it, work has to be done.

But the point is they don't have to update even if there's changes. They can update at their leisure.

Re: Write libraries instead of services, where possible

#152
post #39

Services usually depend on databases. Libraries usually don’t. Either you need to support every storage backend your users might have, require them to write an integration layer from your generic hooks, or expect them to provision and manage new storage when using your library. In any case you are asking them to do a lot more work (manage the data) and in some sense breaking encapsulation by making them responsible f…

This shows that we lack good abstractions over storage.

But that and abstraction exist, because SQL exists.

If the library is designed to send sql to another storage library...

Re: Write libraries instead of services, where possible

#153
post #70

Earlier quoted context omitted.

No? If you have a horizontally scaled architecture or anything with multiple nodes, you can't just get away with "sqlite is a library".

Almost all software is multitenant / easily shardable in some way. Ans almost all software can easily run on a single machine.

Most private software is, but there's an awfully large amount of publicly served software that can't fit into this model (also, any software that has network effects like twitter).

Re: Write libraries instead of services, where possible

#154

Earlier quoted context omitted.

I don't see the issue here. If I release my_fancy_lib 2.0.0, and I have users who only ever want to stay on the last 1.x release, that's fine. It's no skin off my nose if users choose to stay on an old version forever.

Yeah, exactly. However, if you were to make it a service, those users would have to switch to 2.0.0 or stop using it, as 1.x no longer exists.

Some people don't think like that when they write software. They view it as a knife, not a noose.

I prefer those people.

Re: Write libraries instead of services, where possible

#155

Earlier quoted context omitted.

You cannot abstract away a 3 order of magnitude difference in bandwidth and latency.

Where did you get a 3 order of magnitude difference? Are you still using hard drives for your storage medium?

Adding two numbers together takes on the order of a nanosecond. Doing the same thing using a rest / http service (like an idiot) in the same datacenter takes on the order of a millisecond. Six orders of magnitude actually.

Re: Write libraries instead of services, where possible

#156
post #114
post #110

Libraries and services both have maintenance costs and upgrade impedance from clients. The costs might differ, but in my experience work out to about the same overall. The correct way to determine whether a piece of software should be a library or service is by examining its intended purpose and its dependencies. - If the software is dependent on another service or a data store, it should be a service: this provides…

It’s not an either or. As argued elsethread, it should arguably always be a library (though not necessarily a published one), and optionally (if needed) also a service that wraps the library.

If the code is included in the service, it's not a library. If it's packaged as a library and the service code is a (minimal) wrapper around it, it's a pointless additional complexity.

Re: Write libraries instead of services, where possible

#157
post #7

Is this really a common scenario where there's a choice between these 2 options that isn't obvious? I've never considered libraries and services to be two equal options of distributing functionality, and you just pick one of them. It's usually a function of practicality and monetization.

Exactly. I've never run into a situation where there was even a choice. Is it something that relies on a private database, queue, massive processing, dedicated hardware, shared state, something geographically distributed? It's a service out of necessity. Or is it just a bundle of quickly executing code? Then it's obviously a library. I've never seen anybody try to turn leftPad() into a service.

I've seen plenty of engineers try to turn trivial functionality like that into a microservice "to avoid version upgrade hell" (quote from one person in a previous job), or bundle what should be a simple self-contained (i.e. no-dependencies) library of functions (i.e. an API) into a REST/gRPC interface service. Microservices fad-following is as bad as TDD in this industry.

Re: Write libraries instead of services, where possible

#158

Earlier quoted context omitted.

Yeah, exactly. However, if you were to make it a service, those users would have to switch to 2.0.0 or stop using it, as 1.x no longer exists.

Some people don't think like that when they write software. They view it as a knife, not a noose. I prefer those people.

I'm writing from the perspective of the user (which may be a developer using your product in their product). I don't really care if you view software as a knife or as a noose, I don't want to be coerced by the threat of either.

Re: Write libraries instead of services, where possible

#159
post #151
post #72

Earlier quoted context omitted.

I don't quite understand what you are saying. As per the article, the advantage of a library over a service is that you don't have the burden of maintaining the said service. How having a thin client and a server helps? I also don't see how "shoving new options in the dict" can help. From my POV, if the client needs to be updated to benefit from the new features, then there is no way around it, work has to be done. F…

> From my POV, if the client needs to be updated to benefit from the new features, then there is no way around it, work has to be done. But the point is they don't have to update even if there's changes. They can update at their leisure.

Same as not linking with the new lib?

I understand it may be different if the software is distributed through the package manager of linux distribution because you have to follow what's provided by the distribution. But for a commercial software you can probably bundle your own libraries in executable or compile it statically.

But I am not familiar with the difficulties of the above process so I am probably missing something.

Re: Write libraries instead of services, where possible

#160

I've been writing services... as libraries first. Then just wrap the library in a very simple `main()`: ``` #include "servicelib.hpp" int main(int argc, char argv) { return servicelib{argc, argv}.run(); } ``` The library can be re-used in other apps or services. Then the whole damn library is unit-testable with any arguments you throw at it. Got an OS where argv may be null? You can unit test that. Got a user who dec…

We usually wrap a set of valgrind debugged small test/demo programs that hammer a library to monitor for leaks etc. However, ensuring thread safety can sometimes be a challenge. =)

We run unit tests with ASAN. Good test coverage gives us good confidence in safety.

I recently picked up a subscription to undo.io and I figure the next time I see any problem then I'll take that for a spin. I've seen trouble with gRPC and trying to debug it is infuriating.

Post reply on HN