7 ms·
Write libraries instead of services, where possible
- mooreds 3y agoI think this sentiment is a partial cause of the trend towards self-hostable, downloadable software too. The customer has a cost when they operate a library instead of consume a service, no doubt. They also get more control (no surprise upgrades, availability is their responsibility) and assurances (no worries about the service suddenly being end of lifed).
- taneq 3y agoWhen you use a library from an outside source, if you update that library, it might break your build. When you use an outside service, they might break your system at a time of their choosing.
- mooreds 3y agoExactly. It'll break sometime (it's software). So when do you want it to break? And is the benefit of controlling/planning the timing of that breakage worth the cost of operating the software? As always, it depends. Questions I'd ask: * How critical is the software to your application's proper functioning? * How big is the team? * Who are your customers and what are customer expectations around your application's proper functioning? * How often does the library change? * What expectations does a service set around backwards compatibility? What commitments are made?
- nijave 3y ago>When you use an outside service, they might break your system at a time of their choosing. Well sure, but if this is important to you, you might consider a contract with the company that lays out cases and conditions where breakage is acceptable.
- marcosdumay 3y agoOr you internalize the functionality with a library.
- TeMPOraL 3y agoYes, SLA is a way to turn literal existence of a product into a pay-as-you-go offer on top of a service.
- JohnFen 3y agoYes. And if an updated library breaks you, you can fix it easily by rolling back to the earlier version of the library. If an outside service breaks you, you're hosed until they fix the service or you rework your code to route around the breakage.
- mooreds 3y agoPrevious discussion: https://news.ycombinator.com/item?id=26398960 https://news.ycombinator.com/item?id=26398960
- ChrisMarshallNY 3y agoI thought it sounded familiar. Thanks!
- mooreds 3y agoHN doesn't repeat, but it sure does rhyme. :)
- _ZeD_ 3y ago(so that I can use your library and not depend on your service)
- cosmolev 3y agoIt was like this 20 years ago. "software that can be run by the user" - good old times.
- closeparen 3y agoServices 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 for this.
- z33k 3y agoGreat point. In my opinion it is possible and maybe even ideal to do both: make it easy for anyone to run their own service while also running your own service so that users have the option to not have to manage the data, patching and ops side.
- bee_rider 3y agoThe underlying point of the post seems to be that it is better to ask the user to do more work, than the developer.
- Kinrany 3y agoThis shows that we lack good abstractions over storage.
- osigurdson 3y agoYou cannot abstract away a 3 order of magnitude difference in bandwidth and latency.
- pclmulqdq 3y agoWhere did you get a 3 order of magnitude difference? Are you still using hard drives for your storage medium?
- osigurdson 3y agoAdding 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.
- hbn 3y agoIs 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.
- marcosdumay 3y ago> Is this really a common scenario where there's a choice between these 2 options that isn't obvious? In my experience, no, it isn't any common. But it is somewhat common for people to ignore the obvious option and go for services anyway.
- crazygringo 3y agoExactly. 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.
- sokoloff 3y agoFair to assume it’s a joke, but: http://left-pad.io/ http://left-pad.io/
- sidlls 3y agoI'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.
- citrin_ru 3y agoIn my experience a new micro-service considered the default option for anything which could be done as a micro-service nowadays. Library API design is the lost art (almost). And the choose is not always obvious for non-technical reasons. Consider a following example: you have 3 micro-services X, Y, Z which need to interact with a platform G but this interaction requires non-trivial chunk of code. It can be done as a library or as a new adapter micro-service A which will encapsulate knowledge about platform G and will interact with X, Y, Z the way it would be easier for X, Y, Z developers to integrate. Micro-service will add network latency but will allow to make/deploy all changes only to service A. With a library one would have to test and release a new version and then ask X, Y, Z maintainers to switch to this new version. In some organizations it will be a very slow process because X, Y, Z can put an update request (from the library team) at the bottom of the backlog. With a micro-service A teams X, Y, Z would have much less power to stop/slow development.
- sameg14 3y agoYeah but then who is responsible for maintaining the library? If you have a bunch of internal teams that depend on your library and there is an issue or a feature request, you're back to the same position of being the one that does the work to implement. Better to have a service IMO, you can get telemetry out of it and scale it out or replace internals without having to worry about who will get affected.
- sidlls 3y agoMany engineering organizations have "platform teams"--teams that have as their sole responsibility maintaining shared libraries and "core" services for the entire platform.
- marcosdumay 3y agoAs opposed to being responsible for maintaining and doing operational support of the service... I still don't get what advantage exactly you are expecting. Scaling it is only ever a problem for the service; you don't even have to think about it in a library. You can get telemetry from a library just as well as from a service; your users may find that a bit invasive, but it's still way less invasive than calling your service. And you can replace the internals of whatever, without having to worry about who will get affected, that's what defines internals.
- hamandcheese 3y agoIf you can maintain a stable service API, why can't you maintain a stable library API? I don't see any inherent reason why it should be easier to change the behavior of a service rather than a library.
- TeMPOraL 3y agoBecause if you ship code to users (library), you lose control. You may want to change something, but your users will just tell you to go pound sand. Conversely, if you keep the implementation on your side (service), you get to control how things work and when things change, and your users don't have a say in this. It's an ownership and control issue.
- taneq 3y agoWrite libraries instead of services. Where necessary, wrap libraries in services.
- buzzy_hacker 3y agoRelated: Who Does That Server Really Serve? https://www.gnu.org/philosophy/who-does-that-server-really-serve.en.html https://www.gnu.org/philosophy/who-does-that-server-really-s...
- psd1 3y agoStallman performs the vital function of pinning the Overton Window to the left, which benefits those of us with more nuanced views. I'm not going to run my own mail server in 2023, etc.
- deleted 3y ago[deleted]
- slifin 3y agoI hope GraalVM's Polygot runtime will eventually allow more companies to go with libraries over services in more situations for multi-language businesses. And Polylith for better reuse across projects generally.
- pas 3y ago> Polylith this sounds very nice on paper (it sounds common sense trivial utopia that everyone sets out to do anyway, but somehow life, entropy and deadlines get in the way), but ... is there a bigger real life project using something like this?
- cornfeedhobo 3y agoI wish I could nuke GraalVM from the earth. It ruined my life for 2 years and I will never forgive it. It's a very stupid idea, pushed by CTOs that think Java's "write once, run everywhere" is still relevant. It literally runs every language slower and introduces all kinds of build pains. Ugh, I can't believe I had to read your comment this morning. smh
- eurekin 3y agoI was stumped the first time I read about Graal. It felt like 15 years too late and made zero sense to me. Please, if you could share more about that, I'd be happy to share the pain
- deleted 3y ago[deleted]
- wqtz 3y agoI don't get it. Can anyone kindly share where this practice can be applied to a commercial software? I am struggling to wrap my head around "how run by user" works where they are using a commercial software service.
- Sanzig 3y agoLicense fees, just like the old days. Either fixed cost to license the library, a royalty based scheme (# of users/installs), or both.
- denton-scratch 3y agoThere's some confusion in this thread between "service" as out-of-process functionality called via IPC or over the network, and "service" as something done by a service-provider for money, such as emptying your bins.
- catern 3y agoUltimately, it can't. Proprietary software has fundamental limitations that force proprietary software developers to choose technically inferior designs. It's why in the long run proprietary software is doomed.
- NBJack 3y agoIt's all fun and games until you hit version n+1 or n+2, and often realize how slow many customers are to upgrade the library. Then there are the potential conflicts in your own dependencies. And let's not forget the occasional breaking change you introduced. You are now sacrificing the money saved by not hosting to maintain what will likely be a growing matrix of possible versions, underlying assumptions, and my personal favorite: weird customer deployment scenarios that break your library functionality. Bonus points if you are developing in a language without strong typing, or need to integrate with a dependency manager. Plus, if there was anything about your service that leveraged unique algorithmic improvements or some other proprietary tech, it is now at the mercy of anyone with a decompiler and sufficient time. I suspect the author may change their mind if exposed to scaled up solutions and technologies.
- mooreds 3y agoI thought the author addressed that point: "But this assumes that slow-to-upgrade users can have negative effects on everyone else. If one user can't have a negative impact on other users, then you don't care if some users are slow to upgrade; they're only hurting themselves." There's still the support issue, I agree. If a customer paid you money and they are on version n-10, they still expect support. > Plus, if there was anything about your service that leveraged unique algorithmic improvements or some other proprietary tech, it is now at the mercy of anyone with a decompiler and sufficient time. This is a valid point. My answer would be: it's all tradeoffs, but if your secret sauce is so valuable that it would be worth decompiling and can't be protected with decent pricing, license terms and lawyers, run a service. There are plenty of technologies that are not worth decompiling for your average business customers.
- LtWorf 3y agoIf your updates don't break every single time, your customers will be more likely to do them.
- jampekka 3y agoIn my experience the more they try to hide the sauce the worse it is. Quite logical though if the secret is that your secret sauce is bland and off-flavor copy of a canned soup. Which it usually is.
- throwaw12 3y ago"where possible" is a keyword here and easy to argue about. For example: * my logic requires a database * my logic should be isolated for compliance reasons * my logic accesses a service which is not available for everyone * my logic should be processed async and needs to store state, how do I make sure library owners have that environment * customers embedding my library are not upgrading it frequently, which leaves us to support 15 years of libraries * ...
- leethomas 3y agoHm, it feels like all of these except for number 2 and the last one can be solved by appropriate interfaces and documentation.
- mooreds 3y agoOn that topic, I love this article from Stripe (in 2017) about how they version their APIs: https://stripe.com/blog/api-versioning https://stripe.com/blog/api-versioning
- throwaw12 3y agohow about 3? Scenario: your service is accessing a service which exposes PII data and you only process them. Service which embeds your service enabled audit logs of network requests and made it visible to everyone in the company. You have created a risk unintentionally
- throwaw12 3y agohow about 1? Imagine a scenario, your service is a low traffic, but service which embeds you as a library is a high traffic with many instances and always opens DB connection. Why should you optimize your Database for high traffic use case, when your use case is really a low traffic? And then repeat this for 10 other libraries and library owners. Everyone is optimizing for nothing. make it even more difficult, 100 different types of services with different traffic patterns are embedding your library with different behaviours when it comes to managing DB connection state
- whalesalad 3y agoIt’s hard when you have N services that need a lockstep migration from v1 to v2 of the library. I tend to agree with much of this but it’s not a one size fits all thing.
- jampekka 3y agoAnd write unix-style cli tools that can be piped to and from. Make them eat and spit something structured like JSON.
- JoshTriplett 3y agoNot as a primary interface. By all means provide a wrapper around the library that does that, for users to use on the command line, but there should be an underlying library for other programs to use.
- jjtheblunt 3y agoIsn’t powershell a generalized version of that idea?
- jampekka 3y agoIt's a specialized version of that idea. Problem with libraries are that they tie the user to a specific language/OS. A cli tool eating and spitting ASCII/UTF-8 is about as cross platform as it gets.
- throw555chip 3y agoNo actually, it tries to be a kitchen sink and is the opposite of the UNIX concept of pipelines with small purpose built utilities.
- romankolpak 3y agoi get the benefit of offloading the admin costs onto your consumers, but, as always, the devil is in the details. i've met both cases where a library should've been a service, and vice versa. this advice is way too broad and abstract to be practical
- revskill 3y agoWhy not both ?
- 3cats-in-a-coat 3y agoThose aren't "either or" things. Usually services are exposed through libraries. And a library requires a service if it has a canonical or centralized storage or processing, which can't be done locally. Now, sure, we do stupid things as services, for sure. But people often do it to monetize the service, or control the users. And so that'll never change. I recall someone making an "async HTML5 AJAX blink service" as a joke for this trend.
- osigurdson 3y agoIf this isn’t obvious, we are lost. Creating a rest endpoint where a library would do is pure insanity.
- Micoloth 3y agoAnd yet.. I wholeheartedly agree with your sentiment. Unfortunately, the obvious economic incentive to effectively paywalling code through the Internet, is so strong that on this very website (that was supposed to have hacker mentality) most of the comments are in favour of it, because “you have to make a living”… Yes, I think we are lost.
- fragmede 3y agoIf you have any feasible ideas that could plausibly work where people don't "have to make a living" so that we can find ourselves and not be lost, we're all ears. Until then we're stuck in a place where people need money to pay for frivolous things like "food" or "rent" or "transportation". Still, in the face of that, there's a site called GitHub where people do freely share code, despite the economic misincentives, so I think the kids will be alright.
- vinyl7 3y agoThere was a time when software was sold in boxes...
- NohatCoder 3y agoOf course the prevalent reason to make a service is that it can be monetized to Hell and back again. Does it fit the customer's needs? Who cares, as long as they have no clue what they will end up paying until it is too late to migrate away.
- AgentOrange1234 3y agoMeh. Yes that happens and yes it can be frustrating. But… If users want something with long-lasting support and enhancements, that’s going to take work. The people who do this work are going to need to earn a living. There are lots of ways to accomplish this. Advertising, altruism, one time purchases. But charging for a service can be a perfectly reasonable way of making it sustainable.
- lovasoa 3y agoI agree with the reasoning. However, an important point to note is that libraries are much harder to monetize than services.
- jagged-chisel 3y agoYou write a library, then wrap a thin service interface around it. Distribute the lib as needed. Publish the service as needed. Maintain the library, modifying the service on as it is affected. So this effectively comes down to “write a library” as tfa suggests. But there’s no reason the library can’t then be the core of a service.
- soulofmischief 3y agoI take "where possible" to mean that what you describe should be considered an exception instead of a rule, which I agree with. I do have some thin services which are libraries, but above and beyond directly importing libraries is preferred. With edge functions becoming more popular, this also seems to be the preferred pattern, having "fat" edge functions with shared code, vs many small edge functions calling each other.
- mooreds 3y ago> You write a library, then wrap a thin service interface around it. Distribute the lib as needed. Publish the service as needed. At $CURJOB, we did this but at a higher level of abstraction (an authentication architectural component, rather than a library). I think this is what the author means when they say "writing a standalone server reached through a network protocol". We see a lot of folks who like the flexibility of consuming functionality as a service or library, as they see fit. We've even had customers who said "we chose you because now we want you as a service, but later will want you as library" or vice versa. Flexibility isn't free, though. Versioning, support, backwards compatibility (features and performance), even offering the service all become more complex.
- lenkite 3y agoYou can also start calling your library - a "distributable, embedded, natively consumable micro-service" and then other folks start using it. (Believe it or not - this is what some teams in my org started calling a traditional library)
- jagged-chisel 3y agoI support this use of parlance to get everyone onboard :-)
- inetknght 3y agoI'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 decided to use --iamstupid instead of --iamawesome? You can unit test that too. Want to set up environment variables? Well that's not thread safe, but your test harness can do it before it instantiates the library object. Want to use semver? You can. I use git commit checksums for versions and automatic tagging to semver. It's more annoying but superawesome.
- agomez314 3y agoCan you give details on how you do “automatic tagging”?
- inetknght 3y agoCI has a step with a bash script which takes the most-recent tag, bumps it to a new semver, and pushes the updated tag pointing to the commit going through CI.
- jampekka 3y agoHundred times this. Nice to hear an odd sound of sanity amisdt the architecture astronaut crowd. YAGNI.
- Joel_Mckay 3y agoWe 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. =)
- inetknght 3y agoWe 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.
- flatline 3y agoContainers can run services without most of the overhead they talk about. And as everyone else is mentioning here, a service-oriented architecture is not dependent on any one tech stack, it’s just a way of designing applications.
- prpl 3y agoI think this is roughly true, but at a BigCo it’s not really feasible/easy unless you have a monorepo or otherwise extremely good build/integration tooling to deal with many repos (though Go can sort of deal with this) The issue is coordinating changes (and, god help you, library releases) across repos is often an utter nightmare with multiple PR/merge builds
- scubbo 3y ago> it’s not really feasible/easy unless you have a monorepo or otherwise extremely good build/integration tooling to deal with many repos[...] The issue is coordinating changes [...] across repos is often an utter nightmare with multiple PR/merge builds I'm coming up on a year out of $BIG_TECH_JOB (where the idea of a monorepo was horrifying) and transferred to $WAY_SMALLER_NON_TECH_COMPANY_WHO_USES_TECH_JOB (where the enthusiastically use a monorepo), and have been really confused by repeated claims like this. I really feel like I'm missing something here, because lots of obviously-smart-and-experienced folks repeat it. I'd really appreciate it if you could check my understanding and see what I'm missing. (To be clear, here I'm assuming that a monorepo is a single repository which contains conceptually-distinct-but-related projects - things which _could_ justifiably be their own repos, but which are kept in one repo for reasons of maintenance and managements - and wherein the build system is such that every sub-project within the repo uses the same package dependency tree, i.e. if ProjectA and ProjectB in the monorepo depend on LibraryZ, then the versions of Z that A and B depend on must be identical for any given commit/build. If I've misunderstood that - if that's just straight-up not what a monorepo is, or if it _is_ but with some extra nuance or sauce - then I guess we can short-circuit the response pretty quickly :P ) Here's how a release of a breaking change of a library would work in a polyrepo world: * I publish v2.0.0 of my library * Consumers of that library are notified that a new version exists (via automated email notification, Dependabot, whatever) \ * Anyone who _wants_ to update can do so (independently and at their own rate) - anyone who's comfortable staying on the old version can do so ** If we really want to make things easy for consumers, we can make automated PRs against their repos (this would be the "extremely good build/integration tooling to deal with many repos" you refer to, I suspect? Something like Spotify's FleetShift[0]) to make the change - though in practice this is probably way more trouble than its worth, I've only seen it done for serious security vulnerabilities where a) everyone in the whole damn company has to b) upgrade RIGHT THE FUCK NOW. * Time goes by * v1.x gets deprecated * Anyone still using v1.x gets notified that they are using a deprecated version and strongly encouraged to update * A little more time goes by (not much!) * Consequences Occur for people still using the old version - this could be a visit from your friendly InfoSec enforcer, or automatically failing builds, or the removal of v1.x from the package repository (which will indirectly cause failing builds), or... Conversely, with a monorepo, the situation seems to be: * I publish v2.0.0 of my library * Every single team whose code is in the monorepo must coordinate to make the changes to consume version 2. This change, by definition, proceeds at the pace of the slowest team - if one of them is underwater on oncall, or has their only competent engineer on PTO, or has some quirk of implementation (or dependency on old feature) which means they can't update for two months, then _the whole dang monorepo_ is staying on version 1 for two months; no ifs, ands, or buts ** But, yes, if you want to a wide-ranging refactoring to change all the in-monorepo consumers to use the new method, then yeah, modern IDEs are going to have _some_ functionality built-in for that within a single repo. But - by virtue of being a breaking change, it's pretty likely that the change-at-call-site is going to be more complex than simply changing the type or name of the method being called. Maybe the returned object needs different methods called on it. Maybe the method requires an extra parameter (which refactoring IDEs can add to the actual callsite, but cannot implement for you _fetching and providing_ that parameter). At this point, either humans are going to have to comb through the changes to finalize them (at which point, you lose the claimed advantages of being in a monorepo where changes can be done by tooling), or you're going to have to implement some sort of code-parsing system to make correct changes throughout (which, again, is approximately equivalent to the automation work required in the polyrepo case) So: while, yes, it _would_ be a hassle to "coordinate changes across repos" (though _significantly_ less to coordinate across a single repo-to-repo boundary, especially if both are owned by the same team, than it would to coordinate a whole monorepo's worth of interactions), the joy of a polyrepo situation is that _you don't have to_. Consumers can update when they want to, at their own pace - no coordination necessary! So - yes, there will be a greater _volume_ of PRs required in a polyrepo situation, but a) each of them will be way simpler and the total volume of work will be , b) they are independent (so teams who don't want to update do not hold back those who do). But - people keep saying "it's easier to make wide-ranging changes in a monorepo", so I _must_ be missing something. What is it? [0] https://engineering.atspotify.com/2023/05/fleet-management-at-spotify-part-3-fleet-wide-refactoring/ https://engineering.atspotify.com/2023/05/fleet-management-a...
- mpweiher 3y agoNot just instead of a service. Always write a library first. Not for any specific benefits, though these exist, but for architectural reasons. You can trivially wrap a library into pretty much everything else, but not the other way around. In fact, on macOS/iOS I put all functionality in frameworks, as these have structure and can thus contain other frameworks and non-code resources, which is more difficult with a library. https://blog.metaobject.com/2020/06/mpwtest-only-tests-frameworks.html https://blog.metaobject.com/2020/06/mpwtest-only-tests-frame...
- denton-scratch 3y agoWhy does Windows seem to consist largely of a huge number of services? Why do those services seem to have names that provide precious little guidance on what they are for?
- rascul 3y ago> By library, I mean any software that can be run by the user: shared objects, modules, servers, command line utilities, and others. By service, I mean any software which the user can't run on their own; anything which depends (usually through an API) on a service provider for its functionality. These seem to be odd definitions and they make the article hard to reason about.
- yawboakye 3y ago> By library, I mean any software that can be run by the user: shared objects, modules, servers, command line utilities, and others. By service, I mean any software which the user can't run on their own; anything which depends (usually through an API) on a service provider for its functionality. this definition makes (open source) self-hosted services libraries too, and so i think it’s wrong and unusable. the distinction between a library and a service is clear enough and colloquial at this point that a redefinition probably obscures rather than clarifies. a library isn’t runnable (~has no binary), a service is runnable (~has a binary)
- catern 3y agoWhat do you suggest as an alternative way to express these concepts? Colloquially, "library" and "service" have 95% of the correct connotations.
- klysm 3y agoEven executables imo should be very thin wrappers around libraries
- nlawalker 3y agoI have a hunch that a lot of people who have been spurred to think critically about this today are realizing that what they're actually interested in are services (in the economic sense) and not software.
- sidlls 3y agoLibraries 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 the owners freedom to include error handling and observability that is appropriate for the service and provides protection for its dependencies against unbounded access (via observability at minimum, or human-organized contracts, etc.). Examples: software to retrieve user data from a database, software that aggregates data from a user service and an inventory service to produce a purchase history - If the software is self-contained, e.g., it does math or "pure business logic" algorithms, it probably should be a library: performance can be optimized for one or a small handful of common use cases, error handling and observability become the responsibility of clients, and neither owners of the library or clients of it have to concern themselves with the impact to transitive dependencies (e.g., load added to a database). Examples: software that transforms user input into internal serialization formats; software that validates data, encrypts or decrypts data, or otherwise is "purely functional"
- layer8 3y agoIt’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.
- sidlls 3y agoIf 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.
- mgaunard 3y agoThe difference lies in deployment. A library is a piece of code that you embed. A service is already deployed and configured, ready to use. Services provide a much nicer boundary for splitting responsibilities in any SaaS-like organization.
- Manouchehri 3y agoAgreed. Building libraries from multiple private repos is hell in comparison to just having each as their own service.
- Joel_Mckay 3y agoIndeed, because it is easy to keep updated with compatible library package standards ( https://en.wikipedia.org/wiki/List_of_software_package_management_systems https://en.wikipedia.org/wiki/List_of_software_package_manag... ). Docker and Snap core use-case purpose is a necessary compatibility layer. =)
- eikenberry 3y ago90% disagree. At an enterprise scale shop the service model will always win as it will better match the organization structure and avoids the maintenance burden of having to keep a dozen or so libraries in sync. Enterprise shops never standardize solely on a single language as they are filled with exceptions and the new hotness. Everyplace else I'd say it will vary but I agree with the general consensus that shooting for the model of a library that can be easily run as a service is your best approach.
- throwbadubadu 3y agoBut you can add the generic all problem solving run a library as a service service wrapper around it and have both and be done forever?
- Matthias247 3y agoI had the same opinion in the past. But after some more years of work experience - mostly in the managed services area - I don't think it's that clear anymore: - If you offer your users a library, you are competing with tons of open source libraries which claim to offer the same thing. A lot of those will be incomplete, buggy or insecure. But most potential users will never know and try to get them work instead of looking at your offering. - If you are offering a library, debugging and user support can at times be challenging. Do you expect user to look at the internals (source code) of your library? Provide core dumps? - Having to support N different [major] versions of libraries can become challenging. It's hard to know when all users have upgraded. With a service, you can control the update schedule. Even though changes to public APIs of the service certainly are still problematic. - Write a library - but in which language? You might prefer Rust, but your users might prefer Go, Java or Python. You could write the core in one language, and add wrappers in other languages, but some users will still be unhappy with it (e.g. because it makes compilation difficult, people don't want "unsafe C code" in their high level language project, or the wrapper might slow down performance). - Libraries which are general-purpose and are not targetting a specific application/service can over time become feature bloated since things are added "just for the case that someone might need it". This makes them hard to maintain. And since there's no feedback/telemetry, it's also hard to say whether something can be safely removed. Note that all of this doesn't mean "don't write libraries". Even if you write applications/services, its good to structure internal components into libraries. It's mostly about "what is preferrable to offer for users".
- fl0ki 3y agoI also tend to advise people not to write so many services -- a generation of developers has entered the workforce thinking "cloud native microservices" are the only way to factor software of any kind -- but I also caution people not to make everything a library either. Libraries have maintenance costs that have to pay off overall, and I consistently see people underestimate those costs when first making a library. Any library used by more than one project faces friction making almost any kind of changes, especially if the ideal form of the change breaks backwards compatibility even a little bit. Even if it's used by only one project (an unfortunate antipattern some teams fall into), it still introduces friction to individual changes, which is worse in some languages than others because even just testing against a WIP version of the library might be a whole tangle that everyone seems to reinvent "workspaces" to try to mitigate even a little. I now urge people to keep closely related projects in a single repo with purely internal libraries, so you can make backwards incompatible changes because you fix them for all consumers within the same commit that made them. This is like a monorepo but only for closely related projects. It cuts out a lot of the friction of updating shared code, so it's a good way to avoid tech debt and keep both the library and its users evolving. This was inspired by working in an actual monorepo for years, but avoiding the size of repo where you can no longer make every related change in the same commit. When an internal library's API surface has proven to work well for several projects and for long enough to be considered stable, then it can be spun off as a standalone library, and whatever warts slowly form there are probably acceptable in return for the wider reuse.
- tcgv 3y agoIt's not black and white, but primarily: - Libraries are suitable for providing building blocks and common functionality, that you'll build your system on top of, that systems will depend more heavily and execute more frequently. - Services are a strong choice when there's a need to abstract high level operations and architectural complexity. Your system can then focus on making high-level calls without the burden of operating and managing all components and dependencies involved.
- masfoobar 3y agoIn most cases, I write as a library. It makes life sooooooo much easier and can be tested at different levels with unit tests. I will always remember a relatively large GUI application... one big EXE project. All content was hard coded inside Windows/Forms, Button Click methods, etc. I started to break the GUI app down into smaller components. OK.. It has (A), (B), (C), (D), etc. Started to build isolated libraries. I could then test it without having to run the GUI app and get to the respected Window, etc. It made life sooooooooo much easier. Now, it was a bunch of libraries which the GUI apps includes and wraps with presentation. The great thing is that we need to upgrade our tools, opening the door to using a more modern GUI -- as everything is in their own library.. this becomes so much easier to do. This was a C# application using WinForms using .NET framework (v4 something). We upgraded to .NET Core. Once the libraries had upgraded, we decided to use WPF. It was a relatively pleasant experience. Now imagine trying to upgrade .NET version + WinForms to WPF as it currently stood -- all scattered inside the GUI app. My default is to create as library first.
- shantnutiwari 3y agoNote to bloggers: Use CSS, where possible
- deterministic 3y agoThis is so obviously in your face true that it blows my mind that anybody would argue against it. You obviously write a service by linking a networking front-end to a back-end stand-alone library. It’s just basic software development decomposition. Software architecture 101.