Microservices vs. APIS

Microservices vs. APIS

03 Apr 2024
Beginner
13K Views
4 min read

As the topic describes, we will be looking into difference between Microservice and Restful APIs. Before drilling down to the differences, let us first understand each factor individually. To make it easier for you to understand, I will consider Ecommerce site, say Amazon, as an example.

What are Microservices?

Let’s break the word Microservice into two. First, the term ‘Micro’ means small or tiny whereas the term ‘Service’ means some form action which can get your work done. Now combine the both and we have our definition in its easier form.  Microservices are small form of action which can get your work done.

Consider the below scenario. You visit an ecommerce site like Amazon and you tend to do several activities aka request for service like login, searching for product(s), adding/removing product(s) to cart or wish list and so on. If we think of application perspective,

  • When you login, transfer of username and password takes place which Authenticate and Authorize the existence of your account with the Ecommerce site.
  • When you search for a product, it returns a list of options which matches the product name or type of product you searching for.
  • If you want to buy the product you add it to your cart and do a checkout, selects your billing & delivery details and do the payment. And then you receive an invoicing mail.

And many more things you do. Each of these service(s) are handled by dedicated blocks at application level. Such blocks are considered as Microservices, also known as Microservice Architecture.

What are Microservices?

As per https://microservices.io, Microservice is an architectural style that structures an application as a collection of services that are

  • Highly maintainable and testable
  • Loosely coupled
  • Independently deployable
  • Organized around business capabilities
  • Owned by a small team

What are APIs?

Now let us look into Application Programming Interface, also known as API. Let me consider the same service examples I considered to explain Microservices.

  • To Authenticate and Authorize the existence of your account with the Ecommerce site, you send the username and password to your microservice and then someone queries the DB to check if the credentials exist and return the response accordingly.
  • When you search for a product, it returns a list of options which matches the product name or type of product you searching for. To fetch the data as per your search factor, someone takes the search factor from you and queries the DB to get the appropriate response.
  • If you want to buy the product you add it to your cart and do a checkout, selects your billing & delivery details and do the payment. And then you receive an invoicing mail. Someone is responsible to do the calculation, call the payment sites and send the response accordingly. If successful payment, creates the invoice for which all details of product, user are fetched and same gets mailed to the user.

So, the term ‘someone’ who does all the work are nothing but API(s). Below image is updated to point the APIs in our scenario.

What are APIs?

One of the widely used APIs which are used to create microservices is known as RESTful (REpresentational State Transfer) API. They are of different types and are defined using HTTP Verbs. You can visit one of my article which will help you understand details over API.

Differences between Microservices and APIs

So now as you guys have understood Microservices and APIs individually, I m sure you must have also got an presumed the differences between the two. Isn’t it? I am sure you have. But let us check over the difference once more.

  • Microservices can be considered as ‘building block’ to segregate and define different services to have a clean and scalable Architecture whereas API can be considered as the ‘functional block’ to define the work a microservice is responsible to handle.
  • API is a part of Microservice.
  • Microservices can have one or more APIs.
Conclusion

It’s advisable to go with microservice architecture in case of large level applications or if you want to play and plug functionalities. The image you have one more application which can re-use the User Management microservice which you have already created for your previous application. How to connect the microservices with the DB to handle multiple application Authentication, will purely depend on the Architecture your team decides to go for. Monolithic architectures are better to be used for small-scale applications where maintainability and scalability cost are less.

Have you heard about Microservices Architecture is the must-have skills for IT professionals? To enable you to upgrade your existing skills to learn how to implement Microservices in your existing and upcoming projects. Keeping the same in mind, we at ScholarHat deliver an Unlimited .Net Microservices training program that's aligned with real-time with projects implementation.

Share Article
Batches Schedule
About Author
Monalisa Das (Author and Full stack developer)

With a mixed experience of being a Lecturer and now as a core .Net Developer, She hold a strong learning skill over keeping herself updated with the changing technologies in her area as well as other programming language like Python. She enjoy being challenged and working on projects that require her to work outside her comfort and knowledge set. Being a full stack developer, She has hands on over Asp.Net MVC, C#, Vb.Net, Web API, .Net Core, Angular5, Entity Framework (EF), EF Core, Bootstrap, SQL, Postgres to name a few.
Self-paced Membership
  • 22+ Video Courses
  • 750+ Hands-On Labs
  • 300+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Accept cookies & close this