APIs and microservices – what’s the difference?

APIs and microservices – what’s the difference?

Are you confused about the differences between microservices and APIs? Read on for a quick and clear explanation of where they fit into modern approaches to web applications. And how you can use them both to supercharge your development process.

What’s an API?

An Application Programming Interface (API) is a system of structured communication. It lets an application get information from an external service or product using a set of commands. These commands and the information they produce are predictable and usually exhaustively documented.

Here are some examples of APIs in the wild:

  • Need to get a list of all restaurant addresses in your town from Google Maps? Use the Google Maps API.
  • Want to gather account activity from Twitter or search for keywords in old Tweets? Use one of the many Twitter APIs.
  • Want to add secure online payments from PayPal to your application? Use the PayPal API.

APIs include protocols for requests and responses, formats for the transfer of data, and conventions to be followed when interacting with their respective applications.

Ultimately, APIs allow applications to talk to each other and get what they need.

Because the API is standardized, you can be sure that you’ll get a particular response to your request. That makes it easy for you to feed that response into your application and use it for whatever you need.

What are microservices?

Until relatively recently, applications were always programmed as monolithic, self-contained entities. As some of these applications became more complex and unwieldy, it started to make sense to break them up into smaller components. Carve out some functionality, create a separate application, and enjoy the benefits of a smaller codebase, leaner team, and independent development pipelines.

These separate components are called microservices.

Microservices operate independently, so they can use different coding languages and even be replaced or improved without affecting the application as a whole. Microservices even use different databases. They really focus on their own area.

Large companies have been especially active in using microservices. Smaller teams and projects can be easier to manage when you’re dealing with a vast ecosystem such as Netflix or Amazon.

How do APIs and microservices work together?

APIs enable external applications to communicate, but the same process can be used when you break up a single application into microservices. Microservices also use APIs to communicate.

What’s the difference between microservices and API?

Microservices are an architectural approach to designing an application. They are part of a design decision whereby you use small, independent services for individual functionality.

In the microservices architecture, APIs are the communications framework that you use to enable each of the microservices to exchange information.

For example, an online store might be broken up into the following microservices:

  • Product catalog – this contains all the items sold in the store.
  • Orders – when someone orders a product, the order gets tracked here.
  • Payments – the customer pays for their order and the payment is processed in this service.

You can probably already imagine several other microservices, but let’s stick with these for now.

There are inherent advantages to keeping all of these areas separate, especially in a big online e-shop. If there’s a change to the structure of the products offered, there’s no need to mess with the way orders and payments services are coded. The same goes for if something new needs to be added to how payments are processed. There’s no need to change Products or Orders just because you have to update Payments.

So our online store has three microservices. They need to talk to each other.

A customer browses a product and orders it. Products needs to tell Orders what the item is so that it can be correctly pulled from the warehouse shelf and shipped.

When the customer finally decides to pay for the order, Orders needs to interface with Payments so that the correct amount is billed.

None of these conversations need to be very complex. Most of the time, each service is just exchanging a small amount of data and updating its own separate database.

That’s where the API comes in.

Each microservice almost certainly has its own API – its own set of rules for communicating with it. When Products talks to Orders, there are particular pieces of information that Orders needs to receive. It probably isn’t interested in user reviews, for example, but it does need to know the current price of the item.

So a microservice needs to use APIs to talk to other microservices, but APIs are more neutral than that. As we saw above, they can be part of the microservice itself, but they can also be part of other external applications, such as Google Maps, Twitter, and PayPal.

Even better, because of the way that APIs can talk to services without worrying about the internal workings of those services or how they store data, some microservices within an application can be opened up to third parties.

In the same way that Google or PayPal allows communication with their services, our example online store could be given an API to enable another web application to serve data to online reseller or reviewing applications. This kind of integration can become incredibly powerful and lead to new, unexpected uses for data – and increased exposure for the company serving it. For some companies that provide really useful data, APIs can even be monetized directly.

Microservices and APIs are made for each other. The decentralized nature of microservices lends itself to a need for a framework of lightweight, specialized communications. When you get microservices and their APIs really working together, you might be surprised at just what you can achieve.

Blocshop has extensive experience in creating microservices from scratch and converting legacy monolithic systems to microservices. We also have the right know-how when it comes to creating the APIs you need to get everything talking and operating smoothly. Get in touch with us today to get a quote for your project, or even if you just want to have a chat about how microservices could help your business.

Free ebook: From monolith to microservices

From monolith to microservices (ebook): How to break a monolith application into microservices

Leave a Reply

Your email address will not be published.