English | Japanese
This project is a rewrite of parts of the Online Boutique (microservices-demo) demo application provided by Google in Rust.
It is a web-based e-commerce application that allows users to browse products, add them to a cart, and purchase them. It runs on a Kubernetes cluster and the microservices communicate with each other using gRPC. The development languages used are Go, C#, JavaScript, Java, and Python.
It consists of 11 microservices. I have rewritten 4 of these services in Rust.
In the following table, services marked in the Rewrote
column as "Rust" have been rewritten in Rust. Services not marked as "Rust" remain in their original state.
Service | Original Language |
Rewote | Description |
---|---|---|---|
frontend | Go | Rust | Exposes an HTTP server to serve the website. Does not require signup/login and generates session IDs for all users automatically. |
cartservice | C# | Rust | Stores the items in the user's shopping cart in Redis and retrieves it. |
productcatalogservice | Go | Rust | Provides the list of products from a JSON file and ability to search products and get individual products. |
currencyservice | JavaScript | Converts one money amount to another currency. Uses real values fetched from European Central Bank. It's the highest QPS service. | |
paymentservice | JavaScript | Charges the given credit card info (mock) with the given amount and returns a transaction ID. | |
shippingservice | Go | Gives shipping cost estimates based on the shopping cart. Ships items to the given address (mock) | |
emailservice | Python | Sends users an order confirmation email (mock). | |
checkoutservice | Go | Retrieves user cart, prepares order and orchestrates the payment, shipping and the email notification. | |
recommendationservice | Python | Recommends other products based on what's given in the cart. | |
adservice | Java | Rust | Provides random text ads. |
This project was developed by forking the source code of microservices-demo as of March 11, 2024. Updates made to microservices-demo after that date have not been incorporated.
The purpose of rewriting microservices-demo in Rust was to see how a web system running on a Kubernetes cluster would perform in Rust. microservices-demo was just the right size project for learning and experimentation.
For the Rust implementation, I used the axum web framework for the frontend and tonic for the gRPC library.
On the frontend, I adopted a method of splitting the screen into components, where each component generates HTML. This was inspired by React. Despite generating HTML on the server-side, it became a program with a component-oriented approach similar to React. For more details on these implementations, please refer to Rewriting in Rust.
I believe there are still many areas for improvement in this implementation. If you have any suggestions or feedback, please feel free to share them.
Home Page | Checkout Screen |
---|---|
![]() |
![]() |
For information on how to develop this project in Rust, please see the Development in Rust.
-
Install Git, Docker Desktop and Skaffold
-
Select “Enable Kubernetes” in Docker Desktop Settings - Kubernetes
-
Clone the repository.
git clone https://github.com/mnitta220/microservices-demo-rust.git cd microservices-demo-rust/
-
Run
kubectl get nodes
to verify docker-desktop control plane is running. -
Run
skaffold run
(first time will be slow, it can take ~30 minutes). This will build and deploy the application. If you need to rebuild the images automatically as you refactor the code, runskaffold dev
command. -
Run
kubectl get pods
to verify the Pods are ready and running. -
Run
kubectl port-forward deployment/frontend 8080:8080
to forward a port to the frontend service. -
Navigate to http://localhost:8080 to access the web frontend.
-
Cleanup
- If you've deployed the application with
skaffold run
command, you can runskaffold delete
to clean up the deployed resources.
- If you've deployed the application with
-
Ensure you have the following requirements:
- Google Cloud project.
- Shell environment with
gcloud
,git
, andkubectl
.
-
Clone the repository.
git clone https://github.com/mnitta220/microservices-demo-rust.git cd microservices-demo-rust/
-
Set the Google Cloud project and region and ensure the Google Kubernetes Engine API is enabled.
export PROJECT_ID=<PROJECT_ID> export REGION=us-central1 gcloud services enable container.googleapis.com \ --project=${PROJECT_ID}
Substitute
<PROJECT_ID>
with the ID of your Google Cloud project. -
Confirm the services have been enabled for your project.
gcloud services list --enabled --project=${PROJECT_ID}
-
Create a GKE cluster and get the credentials for it.
gcloud container clusters create-auto online-boutique \ --project=${PROJECT_ID} --region=${REGION}
Creating the cluster may take a few minutes.
-
Deploy Online Boutique to the cluster.
kubectl apply -f ./release/kubernetes-manifests.yaml
-
Wait for the pods to be ready.
kubectl get pods
After a few minutes, you should see the Pods in a
Running
state:NAME READY STATUS RESTARTS AGE adservice-76bdd69666-ckc5j 1/1 Running 0 2m58s cartservice-66d497c6b7-dp5jr 1/1 Running 0 2m59s checkoutservice-666c784bd6-4jd22 1/1 Running 0 3m1s currencyservice-5d5d496984-4jmd7 1/1 Running 0 2m59s emailservice-667457d9d6-75jcq 1/1 Running 0 3m2s frontend-6b8d69b9fb-wjqdg 1/1 Running 0 3m1s paymentservice-68596d6dd6-bf6bv 1/1 Running 0 3m productcatalogservice-557d474574-888kr 1/1 Running 0 3m recommendationservice-69c56b74d4-7z8r5 1/1 Running 0 3m1s redis-cart-5f59546cdd-5jnqf 1/1 Running 0 2m58s shippingservice-6ccc89f8fd-v686r 1/1 Running 0 2m58s
-
Access the web frontend in a browser using the frontend's external IP.
kubectl get service frontend-external | awk '{print $4}'
Visit
http://EXTERNAL_IP
in a web browser to access your instance of Online Boutique. -
Congrats! You've deployed the default Online Boutique. To deploy a different variation of Online Boutique (e.g., with Google Cloud Operations tracing, Istio, etc.), see Deploy Online Boutique variations with Kustomize.
-
Once you are done with it, delete the GKE cluster.
gcloud container clusters delete online-boutique \
--project=${PROJECT_ID} --region=${REGION}
Deleting the cluster may take a few minutes.
When updating the source code and deploying it to GKE, build the Docker image for that service with the following command:
docker image build -t <image-name>:<tag-name> .
Then push it to your registry with the following command:docker image push <image-name>:<tag-name>
Replace theimage:
in /release/kubernetes-manifests.yaml with the new image. For example, if you want to update the frontend image, replace:image: masahironitta/microservices-demo-rust-frontend:0.1.0
The /terraform
folder contains instructions for using Terraform to replicate the steps from Quickstart (GKE) above.
- Istio/Anthos Service Mesh: See these instructions.
- non-GKE clusters (Minikube, Kind): see the Development Guide
The /kustomize
folder contains instructions for customizing the deployment of Online Boutique with different variations such as:
- integrating with Google Cloud Operations
- replacing the in-cluster Redis cache with Google Cloud Memorystore (Redis), AlloyDB or Google Cloud Spanner
- etc.
The method for developing this project on a local PC is described in the Rewriting in Rust.
See also original Development guide.
I measured the response time by accessing http://localhost:8080/ using the Thunder Client extension in VSCode after starting it with skaffold run
on my local PC. The results of three measurements for both the original and Rust version are as follows:
Original | Rust version | |
---|---|---|
First time | 52ms | 11ms |
Second time | 13ms | 10ms |
Third time | 15ms | 12ms |