Google App Engine Microservices

vinay mavi
Experience Technology
3 min readFeb 19, 2018

--

Microservices is an architecture of building the application in small connected parts with a different or same technology stack that helps to upgrade and deploy a part of the application independently also enable to multiple teams to work separately on a different part of the application. As an architecture, an application divided into multiple parts if a part is not working then rest application can continue serving to end users.

Google AppEngine is a PaaS service of Google cloud platform. AppEngine offers to deploy applications in multiple languages like Python, Java, PHP, GO with the standard environment, an AppEngine application has inbuilt support to access Google Cloud Platform services also has the inbuilt support of MicroServices, AppEngine application can be divided into multiple parts and every part runs independently in isolation and has access to application-level resources like Google Cloud Storage and Google Cloud Datastore.

AppEngine Microservice Architecture

AppEngine by default run application on default service that served by given app engine URL https://<PROJECT-id>.appspot.com if user wants to deploy a named service then this service run on URL https://<SERVICE-NAME>-dot-<PROJECT-id>.appspot.com.

Setup — Clone Repository

git clone https://github.com/vinaymavi/appengine-microservices.git

This repository contains three AppEngine services

  • python-default
  • python-service1
  • go-service2

with other configuration files.

Repository Structure.

Deploy Python-default service

$ gcloud app deploy python-default/app.yml

validate on — https://micro-mavi.appspot.com/

By default AppEngine deploys application as default service, to deploy named service need to define service name in a .yml file with service key.

#service1.yml file
runtime: python27
api_version: 1
threadsafe: true
service: service1
handlers:
- url: /.*
script: main.app

Deploy pyton-service1

$ gcloud app deploy python-service1/service1.yml

validate on — https://service1-dot-micro-mavi.appspot.com/

Deploy go-service2

$ gcloud app deploy go-service2/service2.yml

Validate on — https://service2-dot-micro-mavi.appspot.com/

Route Request to microservices.

As microservices can be tested on above-provided URLs, it does not support real applications as real applications run on custom domains, to simplify this problem AppEngine provide the inbuilt feature of routing application request to microservices.
dispatch.yml is a configuration file that AppEngine use to map all incoming requests to services.

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

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

# Send all traffic to service1
- url: "*/service1/*"
service:
service1

# Send all traffic to service2
- url: "*/service2/*"
service:
service2

As dispatch.yml file is in place we can test microservices on given URLs

Reference

https://cloud.google.com/appengine/docs/standard/python/microservices-on-app-engine

https://www.toptal.com/developers/all

--

--

vinay mavi
Experience Technology

Vinay is a Cloud Architect, T Shape Developer, Blogger, A Open Source Contributor, Reverse Mentorship Believer.