Google App Engine project can consist of one or more services. When you created an App Engine, it comes with a default service named default. You can add additional services to the application where each service have the following characteristics:
- Code Isolation: each service's code is independent
- Shared Data: Datastore and Memcache are shared between services, however namespaces can be used to isolate data selectively.
- Separate logs for each service and version
- Each service can have different runtime (Python, Go, Java, etc.)
- Each service can have different performance (CPU & RAM) and scaling settings
- Each service can have multiple versions
Reference:
Services: The building blocks of App Engine
Microservices Architecture on Google App Engine
Create a new Service
Assuming you already have an existing App Engine application named hello-app.
Create a separate directory (indepedent of existing project) named hello-service
The setup for a Service is exactly the same as the setup of the default application except additional element in app.yaml. If you are using appcfg tools, you need to specify module element in app.yaml. If you are using gloud tools, you need to service element in app.yaml
Create a project directory for hello-service.
mkdir hello-servicecd hello-service
Create app.yaml with the following configuration. The service shall be named micro.
runtime: python27api_version: 1threadsafe: true# used by gloud toolsservice: micro# the following is required if appcfg tool is used# application: travelopyz# module: micro# version: 1handlers:- url: /.* script: main.app
Create main.py
import webapp2class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.write("I am a micro service")app = webapp2.WSGIApplication([ ('/.*', MainPage),], debug=True)
Deploy the service.
gcloud app deploy -v 1# outputServices to deploy:descriptor: [/projects/hello-service/app.yaml]source: [/projects/hello-service/]target project: [projectid]target service: [micro]target version: [1]target url: [https://micro-dot-projectid.appspot.com]
Open the target url in browser to check if the service deployed succeefully.