Library vs Service: 7 Arguments to consider

Learn what the difference is and when to use which

Martin Thoma
Level Up Coding
Published in
8 min readMay 14, 2021

--

Shared code can be in a library or in a service. Image by Martin Thoma.

Preventing code duplication is a software development principle called DRYDon’t Repeat Yourself. DRY is important because duplicated code usually means way more code that needs to be maintained. If you need to fix a bug, you need to fix it in all duplicated places. If you need to extend the capabilities, you need to do it in multiple parts of the code. When a new developer adjusts one part of the duplicated code and forgets to adjust the other places, the situation gets more complicated.

There are two very different ways to keep your code DRY: Put the shared code in a library or put it in a service. Eric Knipp calls this “shared capability” (source), which already shows that there is an abstraction difference. When you interact with services, you typically don’t want to care about the implementation details of that service. In a library, you might think more about runtime complexity or even jump into the code once in a while.

After reading this article, you will know what the differences between a library and a service are and when you should use one or another. Let’s start!

The differences

--

--

I’m a Software Engineer with over 10 years of Python experience (Backend/ML/AI). Support me via https://martinthoma.medium.com/membership