Code Monkey home page Code Monkey logo

microservices-demo's Introduction

Revamped Online Boutique

This application is based on this repository by Google™

To view the final presentation, click here.

The application is currently deployed here.

About this Application

Online Boutique is a cloud-native microservices demo application. Online Boutique consists of a 10-tier microservices application. The application is a web-based e-commerce app where users can browse items, add them to the cart, and purchase them.

Google uses Online Boutique to demonstrate use of technologies like Kubernetes/GKE, Istio, Stackdriver, gRPC and OpenCensus. This repository contains a revamped version of Online Boutique, that can be run on Google Kubernetes Engine. It's easy to deploy and tear down. Complete step-by-step to deploy and tear down this application can be found on Installation section below.

Screenshots

Home Page Checkout Screen
Screenshot of store homepage Screenshot of checkout screen

Service Architecture

Online Boutique is composed of many microservices written in different languages that talk to each other over gRPC.

Architecture of microservices

Find Protocol Buffers Descriptions at the ./pb directory.

Service Language Description
frontend Go Exposes an HTTP server to serve the website. Sign in (with Google) is not required to browse items and add to cart, but required when checkout.
cartservice C# Stores the items in the user's shopping cart in Redis and retrieves it.
productcatalogservice Go Provides the list of products from Cloud Firestore and ability to get the details of individual products.
currencyservice Node.js Converts one money amount to another currency. Uses real values fetched from European Central Bank. It's the highest QPS service.
paymentservice Node.js 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. Logs order history to Cloud SQL for further processing with Cloud Dataflow, BigQuery, and Data Studio.
recommendationservice Python Recommends other products based on what's given in the cart.
adservice Java Provides text ads based on given context words.
loadgenerator Python/Locust Continuously sends requests imitating realistic user shopping flows to the frontend.

Features

  • Kubernetes/GKE: The app is designed to run on Google Kubernetes Engine.
  • gRPC: Microservices use a high volume of gRPC calls to communicate to each other.
  • OpenCensus Tracing: Most services are instrumented using OpenCensus trace interceptors for gRPC/HTTP.
  • Stackdriver APM: Many services are instrumented with Profiling, Tracing and Debugging. In addition to these, using Istio enables features like Request/Response Metrics and Context Graph out of the box. When it is running out of Google Cloud, this code path remains inactive.
  • Skaffold: Application is deployed to Kubernetes with a single command using Skaffold.
  • Synthetic Load Generation: The application demo comes with a background job that creates realistic usage patterns on the website using Locust load generator. Uses Faker to help generate random email and street addresses.

Additional Features (compared to the official Online Boutique)

  1. Firebase Authentication: The application provides user authentication by Sign in with Google Account and autofill the user's email when checkout.
  2. Firestore & Cloud Storage: The application fetches its products from Firestore, and the product images can be stored on Cloud Storage.
  3. Cloud SQL: The application uses Cloud SQL to store Order information.
  4. Terraform: The application use Terraform to automate creation and teardown of various GCP resources such as GKE cluster, Cloud Storage, and Cloud SQL instance.
  5. Faker & Google Geocoding API: The application generates random users and addresses for load testing, then converts the addresses to geolocation coordinates.
  6. Dataflow: The application uses Dataflow, a fully managed data processing service, to load data from Cloud SQL (transactional database) to BigQuery (analytical database).
  7. BigQuery: The application uses BigQuery, a serverless data warehouse, to enable scalable data analysis.
  8. Data Studio: The application uses Data Studio to quickly visualize the data that have been processed in BigQuery.

Installation

We offer the following installation method:

Running on Google Kubernetes Engine (GKE)” (~30 minutes)

  • You will build, upload and deploy the container images to a Kubernetes cluster on Google Cloud.

Prerequisites

  • kubectl (can be installed via gcloud components install kubectl)
  • skaffold (ensure version ≥v1.10)
  • Enable GCP APIs for Cloud Monitoring, Tracing, Debugger:
    gcloud services enable monitoring.googleapis.com \
        cloudtrace.googleapis.com \
        clouddebugger.googleapis.com

Running on Google Kubernetes Engine (GKE)

💡 You can try it on a realistic cluster using Google Cloud Platform.

  1. Enable Google Kubernetes Engine API

     gcloud services enable container.googleapis.com
    
  2. Run terraform apply in the directory /terraform. Enter your GCP Project ID and then yes.

    It will create GCP resources used in the application:

    Resources Explanation
    GKE cluster For deployment
    Cloud Storage Buckets Product images, Firestore backup
    Cloud Storage Objects Product images
    Cloud SQL Instance Store Order information
    Service Accounts For Firestore, Cloud SQL
  3. Connect kubectl with cluster demo

     gcloud container clusters get-credentials demo --zone asia-east1-a --project <GCP_project_ID>
    
  4. Configuring Firebase Authentication

    • Create a new Firebase Project on Firebase Console and connect it with your GCP Project.
    • Go to Project Settings on the Firebase Console to get your firebaseConfig.
    • Update firebaseConfig here accordingly (necessary fields only).
  5. Configuring Cloud Firestore

    • On the GCP Console, go to Firestore and select Native Mode.
    • Copy firestore-backup to the Cloud Storage Bucket created by Terraform
      gsutil cp -r firestore-backup/content gs://<Project ID>-firestore-backup
    • Import Firestore backup from the Cloud Storage Bucket
      gcloud firestore import gs://<Project ID>-firestore-backup/content/
    • On the Firestore interface, update the value of picture field on each products because your product image links are different. Change them to https://storage.googleapis.com/<Project ID>-product-image/xxx.jpg.
    • Update projectID for the Firestore client here.
    • Create a new JSON key of the service account firestore-sa created by Terraform, and save it on directory /src/productcatalogservice.
    • Update your JSON key file name on .gitignore, Dockerfile, and code.
  6. Configuring Cloud SQL

    • Terraform has created Cloud SQL instance and service account needed by the application.
    • Create Kubernetes secret
      kubectl create secret generic order-secret \
          --from-literal=db_user=root \
          --from-literal=db_password=<GCP_project_ID> \
          --from-literal=db_name=order
      
    • Update project ID for Kubernetes service account annotation on yaml.
    • Update Cloud SQL instance connection name on yaml and code.
  7. Enable Google Container Registry (GCR) on your GCP project and configure the docker CLI to authenticate to GCR:

    gcloud services enable containerregistry.googleapis.com
    gcloud auth configure-docker -q
  8. You can turn off order load generator by setting tasks > checkout here to 0. Else, the generated addresses are processed with Geocoding API. Don't forget to enable it.

  9. In the root of this repository, run skaffold run --default-repo=gcr.io/[PROJECT_ID], where [PROJECT_ID] is your GCP project ID.

    This command:

    • builds the container images
    • pushes them to GCR
    • applies the ./kubernetes-manifests deploying the application to Kubernetes.

    Troubleshooting: If you get "No space left on device" error on Google Cloud Shell, you can build the images on Google Cloud Build: Enable the Cloud Build API, then run skaffold run -p gcb --default-repo=gcr.io/[PROJECT_ID] instead.

  10. Find the IP address of your application, then visit the application on your browser to confirm installation.

    kubectl get service frontend-external
    

    Troubleshooting: A Kubernetes bug (will be fixed in 1.12) combined with a Skaffold bug causes load balancer to not to work even after getting an IP address. If you are seeing this, run kubectl get service frontend-external -o=yaml | kubectl apply -f- to trigger load balancer reconfiguration.

  11. Authorize the domain for Firebase Authentication

    • Go to Authentication section on the Firebase Console and enable Sign-in method: Google.
    • Add the IP address of your deployed application to the Authorized domains.

Cleanup

You can run skaffold delete to clean up the deployed resources.

Conferences featuring Online Boutique


This is not an official Google project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.