PRIYANKA VERGADIA: You've gone through the migration process
and are ready to move your first microservice to GKE.
In today's episode, let's see how.
[MUSIC PLAYING]
CARTER MORGAN: Let's consider the Ice Cream Theory, which
is an online ice cream parlor.
They're on this journey to migrate their monolith website
to microservices, and they're looking for guidance
in moving their first microservice to GKE.
So we'll walk them through the migration in stages.
PRIYANKA VERGADIA: Well, we'll need
to run an assessment of their current environment
to determine how many public endpoints we will need
and what needs to move.
But we'll get to that in the next episode.
For now, let's assume that they have picked up
a feature that makes sense to start with this migration.
CARTER MORGAN: Before we start converting their chosen feature
to a microservice on GKE, let's see how to prepare their GCP
environment.
PRIYANKA VERGADIA: Well, before they migrate the legacy
components, they will need a place to put them.
And for that, they will need a GCP organization.
CARTER MORGAN: Then they need to ensure
that only people with the right authorization
can access the resources, so they
need to design GCP policies to control access
to the GCP resources.
PRIYANKA VERGADIA: And once that's
taken care of, it's time to create a plan
to deploy the resources in a standardized reproducible
way using infrastructure as a code
utilizing tools like Deployment Manager and Terraform.
CARTER MORGAN: At this point, we recommend the Ice Cream Theory
team to study GKE and its features
so that they can tweak them for their needs.
This will mean changing some of GKE's defaults
and maybe hardening the cluster security.
PRIYANKA VERGADIA: Once GKE is set up,
it's time to build the CI/CD pipeline.
They can use their existing tools
like Spinnaker or Jenkins, or they can use the GCP products
like Cloud Build and Container Registry
to build, store, and scan those container images.
Doing this early in the project will avoid problems
when they are in production.
CARTER MORGAN: And remember the last episode
where we discussed communication options between Google Cloud
and on premise's data centers?
Well, they would need to decide whether an API-based solution
like Apigee or a private connection like Cloud
Interconnect is better for their needs.
PRIYANKA VERGADIA: Now that we have our GCP environment set
up, which is kind of like preheat
the oven to start the actual cooking,
it's time to start migrating the legacy platform or with GCP.
CARTER MORGAN: Overall, we recommend that Ice Cream Theory
migrate there features of the website one by one
to the new environment creating microservices will require.
Those microservices can call back to the legacy system
whenever they need.
PRIYANKA VERGADIA: Migrating in stages
like this has two advantages.
Smaller projects are easier to work with, minimize errors,
and costly mistakes, and it lets you
handle each individual migration without getting overwhelmed.
CARTER MORGAN: The first thing to analyze
is the dependencies of the shopping cart feature
on the rest of the system.
We can do that by reasoning through the steps
the user takes when interacting with the website.
The user makes the ice cream selection and clicks
Add to My Shopping Cart.
That triggers an API call from the user's browser
to the shopping cart.
Once the shopping cart receives the call,
it checks whether the chosen ice cream
is in stock by making an API call to the inventory system.
If the item is in stock, the shopping cart stores the info,
something like Carter has one instance of item strawberry ice
cream in the cart.
Finally, when the user checks out
and goes through the payment process,
the shopping cart is queried by the payment subsystem
to compute the total.
And once the payment is complete,
the payment subsystem notifies the shopping cart
feature to empty the cart.
So if we analyze this at a high level,
this shopping cart feature has four dependencies.
It is called by the front end and the payment subsystem,
and it queries a database in the inventory system.
PRIYANKA VERGADIA: Now that we have identified
the dependencies, let's give some thought to the choice
of database for this feature.
A document database is well-suited for storing
shopping carts since shopping carts can be easily indexed
by user IDs, and you don't need the power
of relational database here.
Cloud Firestore is a great fit for this purpose.
It's a managed and serverless no SQL document database,
so let's consider that for our target architecture.
CARTER MORGAN: Now comes the biggest piece,
migrating the actual shopping cart feature.
Assuming Ice Cream Theory can schedule a maintenance
for their website--
PRIYANKA VERGADIA: Wait, wait, wait.
I don't know when is down time for ice creams.
I know I can eat ice creams in the middle of the night.
[CHUCKLING]
CARTER MORGAN: I know.
Well, let's assume that they can do scheduled maintenance.
First, they would need to create a new microservice that
can call the inventory system and uses
Cloud Firestore to implement a shopping cart API.
Then create a script that extracts shopping cart entries
from the legacy shopping cart system
and writes them the Cloud Firestore.
This script needs to be written in a way
that it can be rerun as many times as needed
but only copies the shopping carts
that have been changed since last time.
Then create a script that does the opposite, which
is it copies shopping carts from Cloud Firestore
back to the legacy subsystem in case they need to roll back
the migration.
Then expose the shopping cart API with Apigee.
PRIYANKA VERGADIA: They would need to prepare and test
the modification to the front end and payment systems
so they can call the new shopping cart system.
Again comes the time to run the data migration
script we prepared earlier so all the data is in sync,
and we did not lose any shopping cart records in the process.
CARTER MORGAN: At this point, they
need to put their website in maintenance mode
and rerun the data migration script.
Deploy the tests and modifications
done to the front end and the payment system
on the legacy production system.
Once done, they're ready to disable the maintenance
mode in the website.
PRIYANKA VERGADIA: And with that, the shopping cart feature
of the Ice Cream Theory website is now
microservice hosted on Google Cloud.
The hardest step of this process is
where they had to make changes to the legacy payment and front
end system, but that gets easier as they migrate
more and more features to microservices because more
and more of the dependencies will already be microservices.
As such, they are more loosely coupled
than in monolithic application and are easier to modify
and deploy.
CARTER MORGAN: For more information
about alternative migration approaches,
check out the article written by Marco and Te'o.
PRIYANKA VERGADIA: Well, there you have it.
If you are looking to migrate a monolithic application
to microservices, you've got a small taste
of the steps involved through the Ice Cream Theory's use
case.
Stay tuned for the next episode where
we will talk about deciding what to migrate first.
Until then, try the end-to-end migration
of an e-commerce website in the code lab link below.
CARTER MORGAN: That's all for today
on "Get Cooking in Cloud."
If you like what we're cooking here
and would like to see more recipes,
don't forget to like and subscribe to our channel.