YTread Logo
YTread Logo

What is API gateway really all about? Java Brains - Brain Bytes

Jun 02, 2021
An API

gateway

is an important concept in microservices architecture, it forms an entry point for external clients or

really

anything that isn't part of your core microservice system. By watching this video you will learn all the

gateway

api basics you need to know. you're a back-end developer and you've built an app with microservices your amazing online shopping app now we have a bunch of microservices that discover and communicate with each other using service discovery you have a catalog service that provides the product catalog a shopping cart microservice a search microservice a user microservice everything is great you are very happy with

what

is happening on the server your application API is ready and now you need to deliver it to a front end development team to write the UI client for it in html and

java

script so the front end web developer comes to you and says ok I need to create a UI catalog page is there an API for it ?
what is api gateway really all about java brains   brain bytes
Sure here's the catalog microservice just call it it has rest apis you know ok thanks man and he's off to build his UI catalog page some time later come back to you ok , man, I have the catalog information which is fine, but now I need to display the current one as well. logged in user at the top of the page i don't see that api where is that api? Oh, that's a different microservice,

really

yes, you need to use this user microservice. its page, then it comes back again and says: hi, I also need to display the number of items on the card, where is that API, oh, that's a completely different microservice, that's the shopping cart service.
what is api gateway really all about java brains   brain bytes

More Interesting Facts About,

what is api gateway really all about java brains brain bytes...

You build your UI page, and at the end of the day, you called about 10 different microservices and said, are you kidding me, man, about 20 times? And then the page is finally ready and you deployed it to production. You have a team outing to celebrate your return. k to work to handle production issues and then you realize you should actually refactor your code, the user microservice should ideally be split into a user profile microservice and a session microservice, but wait for the interface type of user, yes, he is using it, so he walks towards it. and say hey listen to that user microservice you're calling, yes you need to update the API because I'm refactoring the code.
what is api gateway really all about java brains   brain bytes
Here are two new microservices you should call now. Are you kidding? think about

what

you did wrong it basically boils down to a very simple concept in computer science you need it to create an abstraction layer there is no reason for the UI guy to know all the details of each and every microservices you have on the backend imagine standing a simple abstraction service that acts as a facade, it doesn't really do anything on its own except that it routes requests and responses made by anyone outside of your microserver system and this abstraction l yesterday is all they need to be concerned about you give this information to the ux guy and voila the sub layer has all the APIs you want to expose to the outside world and when the request comes in it knows what actual micro service to call on that sense, this service abstraction acts like a traffic controller or a router, it forms a single entry point for all your microservices, if you do this you can't split your back into as many microservices as you like or refactor them as many times as you like and have them talk to each other internally as you like, as long as you keep the contract on this fa├žade service, everyone accessing your apis from the outside doesn't even need to know what you're doing inside this facade layer, ladies and gentlemen, is what's called an api gateway, it's as simple as that, it's a gateway, it sits at the edge of your microservice's architectural diagrams, and as a result, it is sometimes referred to as an edge microservice. when people refer to something as an edge microservice this is what they are referring to, so given a microserver system what do you need to do to introduce an api gateway into the image?
what is api gateway really all about java brains   brain bytes
You must first identify what your external API is targeting. each microservice in your system has its own rest APIs, but you obviously don't want them all to be accessible to the outside world. What are the APIs you're okay with other people calling? What will that contract look like? like identify that first layout and build that api then bring in this microservice which will act as a gateway you can write your own or use one of the technologies available there really nothing special about this you are basically building a bunch of apis Based on this public API that you've decided to expose, but all you do internally is call one of your existing microservices and broadcast the response.
This technique is also called API compounding. n api from other existing apis ok so it's for the gateway api ok it can be but here's the thing as you now have the single entry point that all your requests have to go through there is a lots of other things you can do to take advantage of it for example you can add some sort of monitoring system that measures how many requests are coming in how long they're taking and all that stuff this is great for operations and support teams you can authenticate users here. you can pass security tokens like jwt you can implement security measures and prevent things like handling denial of service attacks, prevent access to certain users and ips and much more now if you end up needing to do all these other things then you probably want to avoid typing your own api gateway and look at one of the existing technologies there are a ton of options to choose from a popular option is the open source api gateway implementation of the netflix microservices stack it's called ed zool downloads and you configure zul and run it wherever you run your microservices and there is your api gateway there are other options including nginx and aws hosted implementations no matter which one you choose the patterns are pretty much the same we discuss now the next obvious question which ones are the drawbacks of using the api gateway pattern and how do you fix them?
First obvious downside, you've added a network hop here, so things are going to be a bit slow, but there's really nothing you can do about it. Since the pattern requires a second handicap, let me ask how many of these api gateways do you need? Just create one? Well, one could be a problem. instances went down system will still work what if your api gateway goes down as its a single entry point your whole system goes down as a result which is not good yes you can create multiple gateways api and split your incoming calls using things like load balancers and elastic ips.
The other problem with the api gateway is that it can get a bit tricky technically so lets say you have a web client for your microservices and you have an ios client team and an android team they may need different apis on different gateway configurations in that case instead of overcomplicating the single api gateway you can create multiple types of api gateways, one for each type of client and you can have those clients call the correct api gateway or they configure load balancers that route requests to the correct api gateway. gateway in a nutshell to wrap up our story, what you do is just go to your front end developer and tell him to use your gateway api as the only endpoint you need s to call, listen to a couple of, do you you're kidding me and then once you refactor all your code to call your gateway you are now free to do whatever you want in your microservice architecture as long as you keep this external api contract issue resolved? and thanks for looking at you

If you have any copyright issue, please Contact