Deploying Microservices on Google Cloud
source : Google Blogs

Deploying Microservices on Google Cloud

What is a Microservice? How it is different from Monolithic Architecture? What is the need to use Microservices?

Hold on!!

I'm not going to explain you what a microservice is & it's benefits rather I'm focusing on tell you how to deploy your microservices on one of the most notorious cloud provider ,Google Cloud, but I will give you a small brief about Microservices.

`` A microservices architecture is a type of application architecture where the application is developed as a collection of services. It provides the framework to develop, deploy, and maintain microservices architecture diagrams and services independently.

You might expect I am going to use Kubernetes or any Containerization service, that's a great choice. But Google Cloud provides another simple yet powerful service to create microservice without any containerized code. All you need are just a couple of YAML scripts.

As we all know Google App Engine is a standard serverless computing option for developing and hosting web applications at scale. And it supports various languages include Python, Java, Node & GO etc., Now I'm going to use this service to host my NodeJS server (REST APIs) .

About my Server :

My server is an end-to-end applications which transports data from my Cloud SQL (MYSQL) database to users and upload user data to database. It consists both client APIs and admin APIs in a single code and I deployed it as monolithic server.

No alt text provided for this image

As you know admin end is responsible for large data uploading and it often fails or slows my application performance, so I decided to deploy it as a multi server application i.e using Microservice Architecture.

No alt text provided for this image

Split your code into two parts with defining all the /user routes on one folder and all the /admin routes on another to deploy them as separate services.

Choose any language to write your APIs, Since I’m a node developer I am using NodeJS in this article. Please make sure your source code must contain the standard app.yaml file, which is mandatory to deploy & maintain your applications in Google App Engine. Since we are deploying two applications we need to have app.yaml for each folder, you can specify them as app1.yaml & app2.yaml.

app.yaml files specify the execution environment, version & instance details and also some optional url handlers. Here is the standard app.yaml configuration.

runtime: nodejs16       # or any other supported version

instance_class: F2

env_variables:
? 
	?
#optional

handlers:
- url: /stylesheets
? static_dir: stylesheets


- url: /(.*\.(gif|png|jpg))$
? static_files: static/\1
? upload: static/.*\.(gif|png|jpg)$


- url: /.*
? script: auto
        

And we can deploy this using App Engine standard command :


$ gcloud app deploy app1.yaml app2.yaml
        

This will create a two services for you in a single project with different names, change their names in console as serv-1 and serv-2 to identify those better.

We deployed our code successfully and here what to do next. Inorder to split the traffic for these services we need to create dispatch.yaml file.

The?dispatch.yaml?allows you to override?routing rules. You can use the?dispatch.yaml?to send incoming requests to a specific service (formerly known as modules) based on the path or hostname in the URL. An app can have only one?dispatch.yaml?file, and the routing rules in that file apply to all of the app's services and versions. The routing rules also apply to URLs that are used in a?cron file.

The dispatch file can contain up to 20 routing rules. When specifying the URL string, neither the hostname nor the path can be longer than 100 characters. The standard to split the routing is :


dispatch: 

    # Default service serves the typical web resources
  
    - url: "*/favicon.ico" 
    service: default 


    # Default service serves simple hostname request. 
  
    - url: "simple-sample.appspot.com/" 
    service: default 

    
    # Send the traffic to the serv-1. 
  
    - url: "*/user/*" 
    service: serv-1

    
    # send the to the serv-2. 
    
    - url: "*/admin/*" 
    service: serv-2
                
                          

And deploy this using the same command again


$ gcloud app deploy dispatch.yaml
        

That's it ! Now our application will serve the code from two services which eventually speed up server response and reduce failures.

Since, I'm in the learning stage ,please correct me if I'm wrong. Comments are appreciable! ?

Thank you!

要查看或添加评论,请登录

Siva kumar Katari的更多文章

  • Create React Apps with AWS Support

    Create React Apps with AWS Support

    Hi , Let me start with raising a common pain point of every frontend developer who is going to integrate with backend…

  • How AR changing the Web Experience

    How AR changing the Web Experience

    Well, we might hear about Progressive Web Apps, Accelerated Mobile Pages and Micro Frontends , but the world of web is…

  • What it takes to be an Entrepreneur?

    What it takes to be an Entrepreneur?

    Well, in our last poll which is on choosing "what you want to do in your life?", most of the people choose to start…

    3 条评论
  • Amazing TODO-list app with drag and drop features.

    Amazing TODO-list app with drag and drop features.

    Hello developers/students/LinkedIn professionals, Here's a small app which we all already heard about. Yeah it's…

    8 条评论
  • Challenege on frontendmentor.io

    Challenege on frontendmentor.io

    Hello developers/students/friends, I am siva kumar katari and I want to share my recent accomplishment from…

    5 条评论

社区洞察

其他会员也浏览了