When discussing software architecture and integrations, you’ve likely heard two fancy-sounding terms thrown around: APIs and microservices.
Both concepts are central to web application development and design today, and there’s certainly overlap in their uses. However, it’s important to recognize the differences between microservices and APIs and how they’re applied. This way, you can have more productive conversations with developers and better understand the applications you use and sell.
In this guide, we’ll start by defining both APIs and microservices separately — what they do, and how they work, and why they’re important. Next, we’ll see how APIs and microservices fit together in a modern software ecosystem.
What is an API?
An application programming interface, or API, is the part of an application that communicates with other applications. More technically speaking, an API is a group of protocols and methods that define how two applications share and modify each other’s data.
APIs are necessary in our modern digital infrastructure because they enable standardized and efficient communication between applications which might differ in function and construction.
An API sits between a software’s core components and the public, and external developers can access certain parts of an application’s backend without needing to understand how everything works inside the app. This is what makes an API an interface for programmers.
What Are APIs Used For?
If you use software, you use APIs. That’s because APIs enable software integrations — they allow otherwise separate software entities to share information and function together.
Imagine you’re online shopping and ready to check out. You see that the store you’re on gives the option to pay through PayNow, a payment processor, and you already have an account on PayNow.com with your payment info set up. How convenient!
Since PayNow is a different company from the store you’re currently on, an API facilitates an interaction between the store and PayNow. First, the store uses PayNow’s payment gateway API to request your payment information. Next, the PayNow API fields the request, validates it, fetches the information from its customer database, and sends it back to the store. Finally, the store uses your card information to complete the transaction.
Thanks to PayNow, your store gets all the info it needs to complete your checkout without having to access PayNow’s private database itself, and without requiring you to navigate off the store website.
Exchanges like this occur almost any time two separate applications work together. Some other real-world examples include an embedded YouTube video, a travel website using an airline’s API to access flight times and prices, a website using one of Google’s and/or Facebook’s APIs to allow social login, and a navigation app accessing a public transit system’s API for real-time transportation data.
Since an API is more of a concept, programmers can build an API for their app however they please. However, most rely on frameworks to create them.
REST, which stands for Representational State Transfer, is a framework for developing APIs, and APIs that conform to REST are called REST APIs. REST APIs are the most common type of API for cross-platform integrations and are also used in microservices.
External vs. Internal APIs
Now, full disclosure: The APIs I’ve talked about thus far are all instances of a specific type of API called a web API. Web APIs facilitate communication between web servers. My examples are also all open APIs, which means that they are available for anyone to use, including third-party software developers.
However, API’s don’t have to be publicly available. Internal APIs are used for communication within an application, and access is usually restricted to the organization’s employees and authorized developers. Knowing this, we can now start to unpack microservices.
What is a Microservice?
A microservice is a style of software architecture that divides an application’s different functions into smaller components called “services.” When an application is built this way, it’s said to follow a microservice architecture.
(Quick note: Developers often refer to these smaller components as “microservices” themselves. To avoid confusion, I’ll stick to the term “services” when describing these components, and “microservice” when referencing the entire system architecture.)
For example, the microservice architecture for an application like PayNow could consist of individual services for user account management, integrations with online merchants, and user authentication. Each service works like its own small piece of software within the larger system.
Each service within the larger microservices has just one task, but the scope of these tasks is up to the app’s developers. A basic software application may rely on a few services, as is with PayNow. Or, in the case of large software companies, an application might comprise hundreds of granular services with highly specific functions.
Why Use a Microservice Architecture?
To understand why a microservice architecture is beneficial for software developers, we first need to understand its predecessor, the monolith.
A monolithic application is the opposite of a microservice — instead of assigning different tasks to different self-contained services, every function of the application is handled by a single program.
While it might make sense to start developing an application this way — why create multiple programs to worry about? — adherents to the monolith will encounter issues as their application grows in capability and complexity. Stuffing every aspect of an application into one program makes it difficult to program and release updates, keep track of changes, identify problems, delegate tasks for developers, and generally understand the code.
In other words, everything is so connected inside the monolith that it can be hard to untangle. This created the need for a new type of architecture, hence the rise of microservices. Compared to a monolith, the microservice architecture improves:
Updates: In a microservice application, updating individual services doesn’t require modification of the entire system. This saves time, money, and debugging effort. It also enables rolling updates as opposed to infrequent major updates.
Simplicity: A developer doesn’t have to understand the entire system architecture to understand one aspect of the software.
Team organization: Microservices define boundaries between developer responsibilities. DevOps teams can be assigned to one or more microservices, instead of some portion of a nebulous monolith.
Security: If one service is compromised, it (ideally) won’t affect any other service significantly.
Robustness: Similarly, if one service breaks, other services are unharmed.
Flexibility: If a team wishes to build a service a particular way (e.g. with a different language or framework), they don’t need to worry about how this might impact other components.
To sum everything up: By separating responsibilities, microservices expedite and simplify the software development process.
Of course, a collection of isolated modules won’t do much good for an application, which is why these services are linked together by — you guessed it — APIs.
Microservices vs. API
Before comparing these concepts, let’s quickly review:
An API is a part of a web application that communicates with other applications. A software’s API defines a set of acceptable requests to be made to the API and responses to these requests.
A microservice is an approach to building an application that breaks down an application’s functions into modular, self-contained programs. Microservices make it easier to create and maintain software.
While different things, microservices and APIs are frequently paired together because services within a microservice use APIs to communicate with each other. Similar to how an application uses a public API to integrate with a different application, one component of a microservice uses a private API to access a different component of the same microservice.
Within a microservice, each service has its own API which determines what requests it may receive and how it responds. These APIs typically follow REST principles. Below is a visual example of a basic microservice held together with internal APIs:
Notice how just one module interacts with third-party developers. In our example, this particular service handles integrations with other applications. So, that particular API is public-facing, while all other APIs in this microservice are private.
It’s important to note that no two microservices are alike, and all utilize APIs differently. Some might assign multiple APIs to one service, or use a single API for accessing multiple services. The visualization above is to help you grasp the overall concept of microservices and APIs, but not every application follows a one-to-one API-to-service pairing.
Finally, remember that APIs have uses beyond microservices. As we discussed, web APIs enable data-sharing between systems, which is necessary for many web applications. Also, APIs can be used internally but without a microservice implementation.
The Future (and Present) of Software Architecture
Over the past decade, leading software companies — your Amazons, Netflixes, and Spotifys — have adopted the microservice approach. Sure, their implementations are a bit more complex, but the underlying principle is the same: Breaking up an application’s tasks into software subcomponents makes everything simpler and more efficient, and APIs tie it all together.
If your organization is creating or updating its software infrastructure, it helps to understand these concepts. To this day, APIs and microservices are reshaping not just how software works together, but how people collaborate as well.
Originally published Nov 23, 2020 7:00:00 AM, updated November 23 2020