Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the real difference between an API and an microservice?

I am learning about microservices and I don't understand what the real difference between creating a REST API and creating microservices?
I’m working in Go, but my question applies over all languages.

like image 720
fm433403 Avatar asked Aug 12 '17 23:08

fm433403


4 Answers

The Microservices approach is about breaking your system ("pile of code") into many small services, each typically has its own:

  • Clear business-related responsibility
  • Running process
  • Database
  • Code version control (e.g. git) repository
  • API (the protocol how other services / clients will contact the Microservice)
  • UI

The services themselves are kept small so as your system grow, there are more services - rather than larger services.

Microservices can use REST, RPC, or any other method to communicate with one another, so REST or an API is really orthogonal to the topic of microservices...

Reference: What is an API? In English, please.

like image 195
Lior Bar-On Avatar answered Oct 19 '22 17:10

Lior Bar-On


API = Application Programming Interface

Microservices = an architecture

In short

  • Microservice should expose a well-defined API.
  • Microservice is the way you may want to architect your solution
  • API is what your consumers see.
  • You can expose API without microservices in the backend (in fact, most non-training scenarios don't require microservices).

You may want to read http://samnewman.io/books/building_microservices/ before you decide on using microservices (unless this is for training purposes).

like image 20
Lech Migdal Avatar answered Oct 19 '22 17:10

Lech Migdal


Microservice is well defined when you are following SOC - seperation of Concern on the entity/domain level ,where each entity / domain are independent of any other service.

for example user service will only be responsible for storing, updating and deleting user related informations.

Microservice backend and frontend microservice can further be splitted in 2 parts

  1. frontend microservice which exposes rest endpoint just like Web API
  2. backend microservice which actually perform all the operations.

Rest API is more of endpoints exposed to outer world and can be used with microservices as well, as explained above.

like image 2
Vijay Parmar Avatar answered Oct 19 '22 18:10

Vijay Parmar


The majority of the answers is based on the old-school understanding of API as a programmatic interface. Nowadays, this meaning is melted and start confusing people becuase some developers started (for simplicit or by mistake) interpred the API of an application as the application per se. In such case, it is impossible to distinguish between the modern API and Microservices. Nonetheless, we can say that an API-application can comprise many Microservices, the most of which interact within the application via Microservice's APIs while others may expose their APIs as Applications's APIs. Also, a Microservice (as a service) may not include other Microservices (services), but may orchestrate a composition of Microservices via API-bases invocations. Applications may contain Microservices but, in the best practices, may not contain other Applications.

like image 1
Michael Poulin Avatar answered Oct 19 '22 18:10

Michael Poulin