- Building Google Cloud Platform Solutions
- Ted Hunter Steven Porter Legorie Rajan PS
- 359字
- 2025-04-04 14:47:41
Splitting network traffic
App Engine provides a powerful mechanism for splitting traffic between different versions of a service. This makes it possible to easily implement canary testing, where traffic is gradually rolled over to a new version of a service. For example, a team may decide to allocate 5% of the total network traffic to a new version of a service, and gradually increase traffic allocation to 100%, assuming the service operates as expected. If at any time the service begins to display issues, traffic can be reduced or entirely removed.
To begin splitting network traffic, let's first deploy our Java implementation of the color service. Because our Java service uses the Maven App Engine plugin, we'll leverage that plugin for the deployment. To deploy the Java colors service, navigate to chapter_04/example_03 and run:
mvn appengine:deploy
Once the deployment process is complete, open the Google Cloud Console and navigate to Navigation menu | App Engine | Versions and select colors from the services dropdown. From here, you should see two versions of the colors service—one running on the Java 8 runtime, and the other running on the Go runtime. Because we didn't specify --no-promote in our deployment, the Java service should be receiving 100% of the network traffic.
To split the traffic between both versions of our service, select both versions and click for split traffic. From here, developers can choose to split traffic by IP address, by using a cookie, or at random. For our purposes, select the Random option. Under the Traffic allocation section, specify that each version will receive 50% of the network traffic and click on the Save button:

Now, if we navigate to our default application at https://<PROJECT_ID>.appspot.com, we should see that requests are being routed fairly evenly between the two services. You can then go back to the traffic-splitting menu and modify the rules as desired. For example, changing how much traffic each service receives, or changing the traffic-splitting rule from random to using cookies, illustrated as follows:
