<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Oggy on Medium]]></title>
        <description><![CDATA[Stories by Oggy on Medium]]></description>
        <link>https://medium.com/@uid4oe?source=rss-3b27338da55d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*W9hLhZ5TCQKTc_oRLm2rPA.png</url>
            <title>Stories by Oggy on Medium</title>
            <link>https://medium.com/@uid4oe?source=rss-3b27338da55d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 21:39:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@uid4oe/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Microapps with gRPC-Web]]></title>
            <link>https://uid4oe.medium.com/building-microapps-with-grpc-web-64b7cdf50313?source=rss-3b27338da55d------2</link>
            <guid isPermaLink="false">https://medium.com/p/64b7cdf50313</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[grpc-web]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Oggy]]></dc:creator>
            <pubDate>Fri, 11 Feb 2022 08:16:14 GMT</pubDate>
            <atom:updated>2022-02-11T08:32:13.663Z</atom:updated>
            <content:encoded><![CDATA[<h4>gRPC for Web Clients might boost your organization’s efficiency in an unprecedented way. Here’s how with an implemented flow! (Go, React)</h4><h4>Imagine every team in an organization has the ability to do end-to-end development in their domain.</h4><p>Turning “horizontal teams” <em>(teams that are only responsible from the Frontend or the Backend)</em> to “vertical teams” <em>(teams that are performing full-stack development on a portion of the system).</em> Doesn’t that sounds highly beneficial in many aspects?! Of course, it’s easier said than done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*7FVV4779E8RbpH3uGM6MyQ.png" /><figcaption>Horizontal Teams vs Vertical Teams</figcaption></figure><p>There should be guidelines and tools not only to help teams in developing those blocks but also to maintain coherence over the entire system, especially when it comes down to integration. In such scenarios the importance of standardization is unquestionable. Apart from major improvements in performance, security, and extensibility, code generation by the protocol buffer compiler makes gRPC a perfect candidate.</p><p><strong>Let’s discover how exactly gRPC-Web could help, and go through the steps to make it happen.</strong> <strong>You will also find a flow</strong> <em>(full-stack implementation of Go services with their dedicated React.js pages)</em><strong> as shown below. This flow is used to demonstrate available service method types, in other words, a perfect playground.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bKAuH_a_uN7DtwKVPNNJ2Q.gif" /><figcaption>The Flow</figcaption></figure><p>Utilized service method types and the functionality provided by each step of the flow could be summarized as such;</p><ol><li>Pick a catalog item (<a href="https://grpc.io/docs/what-is-grpc/core-concepts/#unary-rpc"><em>Unary</em></a>)</li><li>Select a real-time generated offer (<a href="https://grpc.io/docs/what-is-grpc/core-concepts/#server-streaming-rpc"><em>Server-side Streaming</em></a>)</li><li>Track the order in real-time and rate (<em>Server-side Streaming &amp; Unary</em>)</li></ol><p><strong><em>TL;DR: </em></strong><a href="https://alva-grpc.web.app/">Demo</a><strong><em>, </em></strong><a href="https://github.com/uid4oe/grpc-web-demo-alva">GitHub</a></p><p>Each step of the flow is designed to represent a “vertical team” as described earlier. Having this mindset, the high-level diagram of the flow is as follows;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j283yeiXpCvEi62OTeegYg.png" /><figcaption>High-Level Diagram</figcaption></figure><p>There are lots of practical examples which demonstrate how to establish communication between microservices using <a href="https://grpc.io/"><strong>gRPC</strong></a>. However, in this story, we will be taking a step further by utilizing <a href="https://grpc.io/docs/platforms/web/basics/"><strong>gRPC-Web</strong></a><strong> </strong>for fast and consistent inner-block communication, e.g. in between a “Vertical Team” UI and microservice.</p><p>It’s totally normal to be overwhelmed or agitated after seeing all the things we are supposed to do to set up such flow. Fear not! You will be truly surprised when realizing how easy it is. The main steps for allowing parties to establish integration using gRPC-Web are;</p><ol><li>Create a .proto file</li><li>Generate code with protoc using our .proto file</li><li>Configure envoy proxy .yaml</li></ol><p>Let’s start with creating a basic <a href="https://gist.github.com/uid4oe/458cc90386727b44cee94bf446527829">.proto</a> file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45385446b260cf7275d2b7af5f21ba8d/href">https://medium.com/media/45385446b260cf7275d2b7af5f21ba8d/href</a></iframe><p><a href="https://gist.github.com/uid4oe/6b999f01ae2ef65d8f11ce83d57757c7">.proto</a> (IDL) is used to define everything we need in our gRPC service. We add all of the required message, service , rpc , enum types here. They will be used by the protoc during the code generation phase.</p><p>Once we are done with the .proto file, we can continue with the code generation phase for the service and the client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t5hb_yPmFd795qupHBp2-Q.png" /><figcaption>protoc &amp; plugins ❤</figcaption></figure><p>For the <strong>service, </strong>we will need two files to be generated by the protoc</p><ul><li><a href="https://github.com/uid4oe/grpc-web-demo/blob/main/1-catalog-service/catalogpb/catalog_grpc.pb.go">catalog_grpc.pb.go</a> <em>(Server, Client, Handler)</em></li><li><a href="https://github.com/uid4oe/grpc-web-demo/blob/main/1-catalog-service/catalogpb/catalog.pb.go">catalog.pb.go</a> <em>(Message)</em></li></ul><p>Running the command;</p><pre>protoc --go_out=. --go-grpc_out=. catalog.proto</pre><p>will generate the aforementioned files in the current directory.</p><p>The same applies to the <strong>client </strong>but<strong> </strong>this time we will get help from the gRPC-Web plugin</p><ul><li><a href="https://github.com/uid4oe/grpc-web-demo-ui/blob/main/src/grpc/catalogpb/catalog_grpc_web_pb.js">catalog_grpc_web.pb.js</a> <em>(Client)</em></li><li><a href="https://github.com/uid4oe/grpc-web-demo-ui/blob/main/src/grpc/catalogpb/catalog_pb.js">catalog_pb.js</a> <em>(Message)</em></li></ul><p>Running the command;</p><pre>protoc --js_out=import_style=commonjs,binary:. --grpc-web_out=import_style=commonjs,mode=grpcwebtext:. catalog.proto</pre><p>will generate the files mentioned above. Notice gRPC-Web plugin offers additional client configuration options such as:</p><ul><li><a href="https://github.com/grpc/grpc-web#import-style">Import Style</a></li><li><a href="https://github.com/grpc/grpc-web#wire-format-mode">Wire Format Mode</a></li></ul><p>Finally, we are required to provide a .yaml configuration for the envoy proxy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gs2BTOPNkgRP9ZB_hNIFUw.png" /><figcaption>Shooting the messenger</figcaption></figure><blockquote>gRPC-web clients connect to gRPC services via a special proxy; by default, gRPC-web uses Envoy. <strong><em>Source: </em></strong><a href="https://github.com/grpc/grpc-web#grpc-web"><strong><em>grpc/grpc-web</em></strong></a></blockquote><p>Please visit <a href="https://gist.github.com/uid4oe/0c07af9984efefe55c8635c43de1ca90"><strong>this link</strong></a> to review a sample configuration. We are adding filters, gRPC-Web related headers, and updating endpoint addresses based on our environment. Building an Envoy Proxy container image with custom configuration is straightforward. Below, there is a sample <a href="https://gist.github.com/uid4oe/0ba918c995c2e7ac3c5a6fd482b40bb8">.Dockerfile</a> which is also used in this demo.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d96fdcd9e10df6831937ac4c139428c6/href">https://medium.com/media/d96fdcd9e10df6831937ac4c139428c6/href</a></iframe><p>By executing the following command <em>(as in the same directory with the </em><em>.Dockerfile ) </em>we should have our custom Envoy Proxy container image ready with a name &amp; tag.</p><p>docker build . -t &lt;name&gt;:&lt;tag&gt;</p><p>That’s it! Fast and consistent integration in just 3 steps. Note that for any update we only need to reflect it on .proto file and re-run the code generation. Another great benefit here is that since all messages and properties inside them are known after the code generation, lots of bugs (either on request or response) that could occur during execution are already prevented!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1SajrjOcjtWMpfHjY8QHsg.gif" /><figcaption>GetItems request over Envoy</figcaption></figure><p>As depicted in the <em>“Shooting the messenger”</em> figure, GetItems flow is initiated by the Web Client, passed on to the Envoy, and then reached to the service, vice versa for the response.</p><p>If you are interested in how to implement a gRPC Service please check the <a href="https://itnext.io/bff-pattern-with-go-microservices-using-rest-grpc-87d269bc2434"><strong>previous story.</strong></a><strong> </strong>The same structure applies to the services in this demo as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7PKgt9GztJIgblNDcGWcCg.png" /><figcaption><a href="https://itnext.io/bff-pattern-with-go-microservices-using-rest-grpc-87d269bc2434">Previous Story</a> / gRPC Service In-depth</figcaption></figure><p>Now that everything is ready, let’s take a closer look at gRPC examples at UI.</p><ul><li><strong>catalogpb.Catalog.GetItems</strong> (<em>Unary)</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9GfzvQS4Ser9c9cR-cNv4Q.png" /><figcaption><strong>GetItems</strong> / gRPC @ UI</figcaption></figure><p>In the above figure, we are importing a message <em>(GetItemsRequest)</em> and client <em>(CatalogClient)</em> from the generated files. Later on, we are preparing our client by giving the URL address of the associated Envoy Proxy and we are good to go! In order to make Unary RPCs, three parameters should be provided.</p><p>client.unary(request: Function, metadata: Object, callback: Function)</p><p>Once the request is completed, the callback will be executed. Based on the result one can update the UI. In this example, we are simply showing an error notification if the gRPC service returns an error. Otherwise, we are converting the response to an object and getting the itemList property that was defined earlier in the .proto message. An example of what a received gRPC error looks like in the Web Client is shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wxeRyvvI7Hi8OrlDI0A_DQ.png" /><figcaption>Sample Error</figcaption></figure><ul><li><strong>offerpb.Offer.GetOfferStream</strong> (<em>Server-side Streaming)</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QdPInTstTfJZLxie4o_x7A.png" /><figcaption><strong>GetOfferStream </strong>/ gRPC @ UI</figcaption></figure><p>Similar to the Unary RPC example, we need to import a message <em>(GetOfferStreamRequest)</em> and client <em>(OfferClient)</em> from the generated files. Once the client is prepared, we can perform Server-side streaming RPCs.</p><p>This time we are setting some properties in the request <em>(business logic)</em> before performing a call. Once the client.getOfferStream() is executed it does return us a ClientReadableStream&lt;GetOfferStreamResponse&gt;.</p><p>By listening to events such as data , end , error on that readable stream, we are able to receive information and update the UI based on different events. Finally, we are unsubscribing from the stream in the clean-up to prevent any memory leaks.</p><p>Still reading? You’re amazing 🤩. Thank you very much for your attention and if you are interested in working with awesome people check us at:</p><p><a href="https://career.alvalabs.io/jobs?department=Engineering">Jobs list - Alva</a></p><p>We are growing super fast. Feel free to fork repositories and start hacking around, everything you need is included. <a href="https://github.com/uid4oe/grpc-web-demo"><strong>Services</strong></a><strong>, </strong><a href="https://github.com/uid4oe/grpc-web-demo-ui"><strong>UI</strong></a>.</p><p>Probably we will hear much more about gRPC for Web Clients when companies start to move towards Microfrontends. Who can say no to built-in speed, performance, security, and robustness, right?</p><p>Also, If your organization has “vertical teams”, it’s likely that they will be able to come up with unique solutions rather than dull repetitions which sounds like an amazing environment for collaboration and growth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P8E74hIMImqRrkyi7xadQg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64b7cdf50313" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[BUILD] BFF Pattern with Go Microservices using REST & gRPC]]></title>
            <link>https://itnext.io/bff-pattern-with-go-microservices-using-rest-grpc-87d269bc2434?source=rss-3b27338da55d------2</link>
            <guid isPermaLink="false">https://medium.com/p/87d269bc2434</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Oggy]]></dc:creator>
            <pubDate>Wed, 08 Sep 2021 19:23:26 GMT</pubDate>
            <atom:updated>2021-09-09T09:41:26.231Z</atom:updated>
            <content:encoded><![CDATA[<h3>[BUILD] BFF Pattern with Go Microservices using REST &amp; gRPC.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vGyfx5FGNH9Tmv-3jBOebA.png" /><figcaption>High-Level Diagram</figcaption></figure><h4>Let’s build dockerized Go microservices demonstrating the BFF pattern with REST and gRPC. Bind it to the UI and deploy everything on AWS EC2. (Also has Kotlin &amp; Java versions)</h4><p>TL;DR: <a href="https://github.com/uid4oe/microservices-go-grpc">Github Go</a>, <a href="https://github.com/uid4oe/microservices-kotlin-grpc">Github Kotlin</a>, <a href="https://github.com/uid4oe/microservices-java-grpc">Github Java</a>, <a href="https://github.com/uid4oe/microservices-grpc-ui">Github UI</a></p><p>BFF, a.k.a. “<em>Best Friends Forever</em>” pattern is a well-established architectural… Jokes aside, the <a href="https://medium.com/frontend-at-scale/frontend-architectural-patterns-backend-for-frontend-29679aba886c">BFF</a> — Back-end for Front-end pattern makes sense when our system has <strong>multiple</strong> Front-ends that have quite <strong>different requirements</strong>. Instead of changing our core services based on different Front-end specific demands, we are aiming to fulfill those in a layer that is in between Front-end and core services. So, we are adding a <strong><em>Back-end service for the Front-end.</em></strong> This also allows us to handle such needs in a structured and bounded context.</p><p>Ideally, our business/domain-related logic should be placed in microservices that are not exposed to the outside world. Such setup supports SoC, modularity, and flexibility. In this example, <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/user"><strong>User Service</strong></a> and <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/advice"><strong>Advice Service</strong></a> will hold our domain logic. <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/bff"><strong>BFF Service</strong></a> will be performing <a href="https://medium.com/swlh/grpc-in-the-life-of-microservices-309933945d6">gRPC</a> calls to the domain services. Also, if required, it will be responsible for aggregating/customizing the received domain responses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KB7Rc7PIJmDmBhvJJy6DPA.gif" /><figcaption>User Interface (React.js with Semantic UI)</figcaption></figure><p>Above, we have our <a href="https://github.com/uid4oe/microservices-grpc-ui">UI</a>. We are going to implement CRUD operations for <a href="https://robohash.org/">robot</a> users and link <a href="https://api.adviceslip.com/">random advice</a> with their <a href="https://github.com/uid4oe/microservices-go-grpc/blob/af856b536b03bee25a5e157b021bb4d26c4ed48e/advice/advicedb/postgres.go#L14">user_id</a>. Well, but based on the <em>High-Level diagram</em> we are storing some parts of the data in different repositories. Does this mean we will need to perform multiple network calls in our Front-end? <strong>No!</strong> BFF Service will handle such scenarios for us. Below, there is a cool gif highlighting the parts that are involved in processing different request types in our example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*YCFbNsJ5njf88b4a0ZoCIg.gif" /><figcaption>The cool gif</figcaption></figure><p>So, we now have this <strong><em>extra</em></strong> service that resolves the aforementioned issues. But what about the Performance. The elephant in the room. To reduce newly introduced overhead we will use <a href="https://medium.com/swlh/grpc-in-the-life-of-microservices-309933945d6"><strong>gRPC</strong></a> between services. Let’s start with defining our contract for the <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/user"><strong>User Service</strong></a><strong>.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d21ce494c6d8faf0aa9cb448227c0b7/href">https://medium.com/media/1d21ce494c6d8faf0aa9cb448227c0b7/href</a></iframe><p><a href="https://github.com/uid4oe/microservices-go-grpc/blob/main/user/userpb/user.proto">user.proto</a> is used to define everything we need in our service. We add all of the required message, service , rpc , enum types here. They will be used by the protoc during code generation.</p><p>To generate the related code we can use <a href="https://github.com/uid4oe/microservices-go-grpc/blob/main/genarate-pb.sh">generate-pb.sh</a> which is basically executing protoc commands.</p><p>Great! The bridge between <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/user"><strong>User Service</strong></a><strong> </strong>and any other service is now ready. We can start implementing the rpc <strong>GetUsers</strong> on <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/user"><strong>User Service</strong></a> (gRPC Server).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1dbf0047b91f5b2d400e569768342be/href">https://medium.com/media/a1dbf0047b91f5b2d400e569768342be/href</a></iframe><p>Above, <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/user"><strong>User Service</strong></a> (gRPC Server) implements the <a href="https://github.com/uid4oe/microservices-go-grpc/blob/af856b536b03bee25a5e157b021bb4d26c4ed48e/user/main.go#L74">rpc </a><a href="https://github.com/uid4oe/microservices-go-grpc/blob/af856b536b03bee25a5e157b021bb4d26c4ed48e/user/main.go#L74"><strong>GetUsers</strong></a> by delegating the request to a method in the <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/user/userdb"><strong>userdb</strong></a><strong> </strong>package which performs DB operations through the <a href="https://github.com/uid4oe/microservices-go-grpc/blob/af856b536b03bee25a5e157b021bb4d26c4ed48e/user/userdb/mongo.go#L77"><strong>mongo_client</strong></a>.</p><p>We are done with the <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/user"><strong>User Service</strong></a> (gRPC Server) and ready to start building the <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/bff"><strong>BFF Service</strong></a><strong> </strong>(gRPC Client). Thanks to protoc , required <a href="https://github.com/uid4oe/microservices-go-grpc/blob/af856b536b03bee25a5e157b021bb4d26c4ed48e/user/userpb/user_grpc.pb.go#L30"><strong><em>stub</em></strong></a><strong><em> (</em></strong>gRPC Client for the <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/user"><strong>User Service</strong></a>,<strong> </strong>or any other<strong>) </strong>is already generated.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cf9ea0adcb0b5f5dafb84b23a6a3011/href">https://medium.com/media/6cf9ea0adcb0b5f5dafb84b23a6a3011/href</a></iframe><p>After setting up our HTTP/2 connection in the <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/bff"><strong>BFF Service</strong></a>, we will use <strong>userGrpcServiceClient </strong>which is our stub (You can name it any way you like) to communicate. When our stub invokes it’s rpc <strong>GetUsers </strong>method, the request will reach to our gRPC Server implementation in <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/user"><strong>User Service</strong></a><strong>. </strong>And that’s it! We are now able to use MongoDB over gRPC and return the response to <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/bff"><strong>BFF Service</strong></a>.</p><p>We are almost done, There are just two things to do left for serving our Front-end. Preparing handler functions and run an HTTP server that binds endpoints to our handler functions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbb6317477eb24a5330d9ee67c8bb00a/href">https://medium.com/media/fbb6317477eb24a5330d9ee67c8bb00a/href</a></iframe><p>Above, the handler function <a href="https://github.com/uid4oe/microservices-go-grpc/blob/af856b536b03bee25a5e157b021bb4d26c4ed48e/bff/main.go#L33"><strong>GetUsers</strong></a><em> </em>delegates the request to <strong>user_client </strong>which contains a <strong><em>stub</em></strong> of the <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/user"><strong>User Service</strong></a> named <a href="https://github.com/uid4oe/microservices-go-grpc/blob/af856b536b03bee25a5e157b021bb4d26c4ed48e/bff/client/user_client.go#L56"><strong>userGrpcServiceClient</strong></a><strong> </strong>as we discussed before.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1341acb3ef10362d39370d419810e95/href">https://medium.com/media/e1341acb3ef10362d39370d419810e95/href</a></iframe><p>Finally, we will be setting up the HTTP server, we are going to use <a href="https://github.com/gin-gonic/gin">Gin</a> in this example. gin.Default() attaches Logger and Recovery middleware. cors.Default() allows us to accept traffic from anywhere. We register our endpoints/routes with their handler functions. Now, once a request is made, Gin will invoke the registered handler function.</p><p><strong>Hooray! We are done!!! </strong>At this point, we can use the repository (MongoDB) of <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/user"><strong>User Service</strong></a><strong> </strong>over gRPC, return the response to <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/bff"><strong>BFF Service</strong></a>, customize it any way we want, and then return to the Front-end.</p><p>The rest of the implementation is available on <a href="https://github.com/uid4oe/microservices-go-grpc">GitHub</a>. If you are interested in a service that is using SQL repository, check <a href="https://github.com/uid4oe/microservices-go-grpc/tree/main/advice"><strong>Advice Service</strong></a><strong> (</strong>PostgreSQL).</p><p>It’s time to <strong>dockerize</strong> our work! First, we will need a Dockerfile</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76e5fcc21d1a5a2e69c74fd308047261/href">https://medium.com/media/76e5fcc21d1a5a2e69c74fd308047261/href</a></iframe><p>We should change the &quot;PORT&quot; with the port value that needs to be exposed. For instance,8080. Then, we can build the app and create an image with docker build -t uid4oe/go-ms-bff:latest</p><p>Also, I prefer using the scratch as it shrinks the final image size quite a bit. We should apply the same steps for the rest of the services and push images to <a href="https://hub.docker.com/">Docker Hub</a>. docker push uid4oe/go-ms-bff:latest</p><p>Finally, we will need a <a href="https://github.com/uid4oe/microservices-go-grpc/blob/main/docker-compose.yml">docker-compose.yml</a> file to gather everything. By default, we can use the file in the link. With<a href="https://github.com/uid4oe/microservices-go-grpc/blob/main/docker-compose.yml">docker-compose.yml</a>we should also copy <a href="https://github.com/uid4oe/microservices-go-grpc/blob/main/mongo-init.js">mongo-init.js</a> , <a href="https://github.com/uid4oe/microservices-go-grpc/blob/main/advice.sql">advice.sql</a> , <a href="https://github.com/uid4oe/microservices-go-grpc/blob/main/.env">.env</a> to our EC2 instance.</p><p>Coming to the end, We can follow the <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html">Amazon guide</a> for setting up Docker in EC2. Afterward, we need to add docker-compose to our instance using this <a href="https://gist.github.com/npearce/6f3c7826c7499587f00957fee62f8ee9#docker-compose-install"><strong>Gist</strong></a>, and now we are all ready! Oh, make sure <strong>inbound rules</strong> are configured properly. By default, ports 80 and 8080 should be accepting traffic.</p><p>Once we run the commands below all the services will be up and running.</p><pre>docker network create uid4oe<br>docker-compose up -d</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*AX9bnAA4oZ3sbRe-6lr_Eg.png" /></figure><p>Wow! that was quite a journey. Thank you very much for your time. All the necessary files are in <a href="https://github.com/uid4oe/microservices-go-grpc">Github</a>. I’m also adding the <a href="https://github.com/uid4oe/microservices-kotlin-grpc">Kotlin Spring</a>, <a href="https://github.com/uid4oe/microservices-java-grpc">Java Spring</a> versions. They are identical to the Go version in terms of functionality. Special thanks to <a href="https://programmingpercy.tech/blog/">Percy Bolmer</a> for reviewing the story.</p><p>Have a nice day!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87d269bc2434" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/bff-pattern-with-go-microservices-using-rest-grpc-87d269bc2434">[BUILD] BFF Pattern with Go Microservices using REST &amp; gRPC</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>