Learning Library

← Back to Library

Direct vs Gateway Microservice Architecture

Key Points

  • The example uses a fictional e‑commerce site, “Indies Custom Threads,” where users order customized T‑shirts via web, mobile, and third‑party API clients.
  • The product‑detail UI is split into several microservices (product info, pricing, order, inventory, reviews) instead of a monolithic app.
  • One possible architecture lets each client call those microservices directly, with the UI making separate requests for info, price, stock, etc.
  • While direct client‑to‑service communication can work for a small system, it quickly generates many API calls as functionality and services grow, making the approach inefficient.
  • This limitation motivates the need for an API gateway or other pattern to consolidate and streamline client interactions with the microservice backend.

Full Transcript

# Direct vs Gateway Microservice Architecture **Source:** [https://www.youtube.com/watch?v=OAdOa31EH4o](https://www.youtube.com/watch?v=OAdOa31EH4o) **Duration:** 00:08:05 ## Summary - The example uses a fictional e‑commerce site, “Indies Custom Threads,” where users order customized T‑shirts via web, mobile, and third‑party API clients. - The product‑detail UI is split into several microservices (product info, pricing, order, inventory, reviews) instead of a monolithic app. - One possible architecture lets each client call those microservices directly, with the UI making separate requests for info, price, stock, etc. - While direct client‑to‑service communication can work for a small system, it quickly generates many API calls as functionality and services grow, making the approach inefficient. - This limitation motivates the need for an API gateway or other pattern to consolidate and streamline client interactions with the microservice backend. ## Sections - [00:00:00](https://www.youtube.com/watch?v=OAdOa31EH4o&t=0s) **Microservice Architecture for Custom T‑Shirts** - A walkthrough of a fictitious e‑commerce storefront illustrating users, web/mobile/third‑party clients, and how its product detail UI is broken out from a monolith into separate microservices such as a product‑info service. ## Full Transcript
0:00so let's start off an example here let's 0:02say we have a fictitious ecommerce 0:03storefront 0:05indies custom threads and in this store 0:07you can order customized t-shirts kind 0:09of like my nifty api gateway t-shirt 0:11here 0:12so let's walk through this scenario 0:13right we have our users here and then 0:16they would make the purchase and look at 0:18the t-shirts on the website through 0:20these different clients right so you'd 0:21have your web application here which 0:23would be a standard web browser 0:25we'd have our mobile client as well it 0:27could be ios it could be android and 0:30then we also have a third-party api 0:32integration service right so this could 0:34be if you want to integrate your website 0:36with like say something like facebook 0:38or in our case we have a review 0:41api that's integrated through a third 0:43party so say you see someone makes a 0:45comment about the t-shirt and they're 0:47like 0:48man the t-shirt fit comfortable but the 0:5150 polyester really gave me a bad skin 0:54rash that would all be possible through 0:56this third-party integrated service 0:59so now that we've established our users 1:01and our clients 1:03now let's take a look at the actual 1:05product detail ui so there's a lot of 1:07different functionality a lot of 1:09different tasks that we've broken down 1:11into these micro services here 1:13and this originally would be a 1:15monolithic application like we 1:17previously talked about but we've broken 1:18it apart and segmented it into different 1:20services so 1:22as you can see the first one here is the 1:24product info service this would be stuff 1:26like you know look at the t-shirt what 1:28kind of color is a t-shirt is it black 1:30red 1:32the size of the t-shirt large medium and 1:34so on 1:35and then we have our pricing service we 1:37have our order service if you want to 1:39look at you know purchase history you 1:41got the inventory service and the review 1:43service and so on and this is just a 1:46handful of different microservices here 1:48we could have many more so just for this 1:51presentation we're going to keep it 1:52pretty simple okay 1:55so the first architecture pattern that 1:57we could operate where we could have 1:59users communicate with these 2:01microservices would be without an api 2:03gateway 2:04and this would be a direct 2:09client 2:13to microservice 2:16i'm just going to put svc for short 2:18communication 2:22so in in this approach in this 2:24architecture pattern 2:25we have our clients speaking directly to 2:28our micro services right so 2:31say that 2:33this user here 2:35goes to the the product detail ui and 2:37wants to look at the product info right 2:39and see what kind of shirt they have 2:42so that it would talk directly to this 2:45service right here um 2:47and then so on if you want to see the 2:49price scene right 2:50does another click on the ui it would go 2:52to this microservice and so on so 2:55this client is speaking to all these 2:58individual services right here 3:00and this is completely fine and this 3:02operates really well for like a small 3:04application but as you start to grow and 3:06add more functionality and more services 3:09to your product ui page 3:11you're going to have many more calls 3:13right api requests 3:15and this is not ideal for that once you 3:17start to grow so 3:19trying to scale something like this can 3:21be very cumbersome and be very 3:22problematic both for the user and the 3:25development team 3:27so let's take a look at some of those 3:28pitfalls that you may run into 3:30the first one 3:32is 3:34too many round trips 3:36you're probably wondering what the 3:37hell's a round trip right well round 3:39trip 3:40in this instance 3:42is discussing 3:44going from the client 3:46all the way to the product info service 3:48right so again say you don't want a 3:50black t-shirt you want a red one 3:52and maybe instead of large you want to 3:54get one for your child who's a youth 3:57size 3:58and 3:59the price goes down 4:01so this service will need to communicate 4:03with this service 4:05but it'll have to go all the way back 4:07call the way back to the client and then 4:09go all the way back to this pricing 4:11service and then all the way back and so 4:13on so as you can see there's a lot of 4:16traffic going across the network here 4:18and this causes a major significant 4:20latency issue 4:23so 4:24the page loads very slow you're going to 4:26have to wait it's not very user friendly 4:28and then again the development 4:30experience is not great for developers 4:32because you got to maintain all this 4:33traffic and there's just so much room 4:35for error using this model 4:37so another issue to think about is cross 4:40cutting right so by cross cutting 4:44this would be the issues dealing with um 4:47the actual internet protocols that your 4:49clients are using 4:51for the most part it's most likely to be 4:53using like https where the s would be a 4:55security credential that you got to get 4:57certified 4:59but every now and then you're going to 5:00have some server-side protocols say 5:02something like amqp 5:04which is advanced messaging queueing 5:06protocol 5:07and you're not able to do that with this 5:10model because 5:11you have to be consistent have the same 5:13common functionality of all these 5:15services right 5:16so you're very limited with your 5:18resource right your resource pool as far 5:20as who can operate and make a purchase 5:22on your site 5:25another issue is security and this is a 5:28big one especially nowadays as we're 5:30seeing more and more 5:31you know 5:32large enterprises being hacked and so on 5:35so 5:37in this model all these micro services 5:40are exposed externally right they're all 5:42public facing so they can operate with 5:44these clients 5:45here so 5:46there's a lot of room 5:48getting hacked right here 5:50so you have a larger footprint that's 5:52susceptible to getting hacked and 5:54you know ideally you would have a 5:56central 5:57hub that could manage that for you'd 5:59have like a layer a barrier um to block 6:02you from all that but 6:05again this is just 6:06in this model 6:08and the last real quick pitfall i just 6:10want to cover briefly is coupling right 6:13so again as we we talked about 6:15previously about the whole monolithic to 6:17micro surface architecture right so 6:19you're taking this large application and 6:22you're segmenting it into smaller 6:23microservices which is great and we've 6:26done that here but 6:28microservices 6:30over time can start to become more 6:31tightly coupled and reliant upon each 6:33other so that's something you want to be 6:34mindful of especially in this 6:37architecture pattern because you have so 6:39many communication channels going back 6:41and forth and again like the product 6:43info service right was relying upon 6:44their pricing service in certain 6:46instances 6:47if this product info service needs to be 6:49maintained and updated 6:51that could be contingent on this other 6:54pricing service if it's operating and 6:55they could affect each other so 6:58if one goes down another one go down it 6:59could have 7:00a cascade effect where you know your 7:02services aren't operational 7:05and then you know again it's all about 7:06your user experience it's not ideal for 7:08a user if one service goes down and 7:10they're not able to operate because 7:11another service goes down 7:13so you really want to try to mitigate 7:15that 7:16so coupling is another thing to be 7:18mindful of in this architecture pattern 7:21so i hope this quick overview of direct 7:22client to microservice communication 7:25architecture has been helpful for you 7:27again it's not a bad option if you're 7:29just going to have one single api that's 7:30only read only 7:32however if you're going to scale out 7:34your application in the future and 7:35you're going to have much more 7:36functionality and features added as well 7:39as having more api requests come in then 7:42you really want to consider implementing 7:44an api gateway to help mitigate all 7:46these issues we went over in the video 7:49so again thank you so much for watching 7:51and please don't forget to hit that 7:53subscribe button as always thank you 7:56if you have questions please drop us a 7:58line below if you want to see more 8:00videos like this in the future please 8:02like and subscribe