Giter Site home page Giter Site logo

mercari-microservices-example's Introduction

Mercari Microservices Example

Let's explore the Mercari-ish microservices consist of Go, gRPC, Kubernetes and Istio on your laptop!

image

Microservices

You can find each microservice's implementation and gRPC API definitions under the /services directory.

Gateway

  • This is the only microservice which is facing the out side of the Kubernetes cluster and acts as just a proxy.
  • This microservice is responsible for authenticate the request by verifying the access token (JWT) with public keys which can be fetched from the Authority microservice.
  • This microservice also transcode the JSON requests to the gRPC Protocol Buffers.

Authority

  • This microservice is responsible for issuing the access token (JWT) for the customer app.
  • This microservice also provides public keys as a gRPC endpoint to make other microservices be able to verify the signature of the access token.

Catalog

  • This microservice is responsible for aggregating data from the Customer and the Item microservices to make an API caller easily consume it.
  • This microservice acts like a Backend For Frontend (BFF).

Customer

  • This microservice is responsible for storing the customer information to the database and providing it as APIs.

Item

  • This microservice is responsible for storing the item information to the database and providing it as APIs.

Usage

Prerequisites

  • Go
  • Docker

Lanuch the Kubernetes cluster

make cluster

This make target does following tasks:

  • Launch the Kubernetes cluster on your laptop by using kind.
  • Install Istio to the Kubernetes cluster.
  • Build Docker images of all microservices placed under the /services directory.
  • Deploy all microservices to the Kubernetes cluster.

After this make target will have been finished, you can check the status of microservices with ./script/kubectl which is just a tiny wrapper for kubectl like below:

./script/kubectl get pods --all-namespaces | grep -E '^(gateway|authority|catalog|customer|item)'
authority   app-7b559dfd9f-dcr2v   2/2     Running     0   44s
authority   app-7b559dfd9f-z8c54   2/2     Running     0   44s
catalog     app-67cc897d9c-dhcv7   2/2     Running     0   36s
catalog     app-67cc897d9c-nfk7x   2/2     Running     0   36s
customer    app-565bfc5884-bgb8r   2/2     Running     0   28s
customer    app-565bfc5884-lt6q2   2/2     Running     0   28s
gateway     app-cc456cf4d-nsghg    2/2     Running     0   51s
gateway     app-cc456cf4d-wq47s    2/2     Running     0   51s
item        app-84db48bdf-h7q7b    2/2     Running     0   19s
item        app-84db48bdf-l5mnl    2/2     Running     0   19s

Now, the Mercari-ish service is listening on port 30000, and you can explore it like below!

API

Sign up

curl -s -XPOST -d '{"name":"gopher"}' localhost:30000/auth/signup | jq .
{
    "customer": {
        "id": "ec1fcc77-b565-4477-b609-62bf0c403903",
        "name": "gopher"
    }
}

Sign in

TOKEN=$(curl -s -XPOST -d '{"name":"gopher"}' localhost:30000/auth/signin | jq .access_token -r)

Create a item

curl -s -XPOST -d '{"title":"Keyboard","price":30000}' -H "authorization: bearer $TOKEN" localhost:30000/catalog/items | jq .
{
    "item": {
        "id": "bda92da6-3270-4255-a756-dbe7d0aa333e",
        "customer_id": "ec1fcc77-b565-4477-b609-62bf0c403903",
        "title": "Keyboard",
        "price": "30000"
    }
}

List items

curl -s -XGET -H "authorization: bearer $TOKEN" localhost:30000/catalog/items | jq .
{
    "items": [
        {
            "id": "3c287306-6753-4ab6-acde-d17297e2939e",
            "title": "Keyboard",
            "price": "30000"
        },
        {
            "id": "e0e58243-4138-48e5-8aba-448a8888e2ff",
            "title": "Mobile Phone",
            "price": "10000"
        },
        {
            "id": "0b185d96-d6fa-4eaf-97f6-3f6d2c1649b6",
            "title": "Laptop",
            "price": "20000"
        }
    ]
}

Get a item detail

curl -s -XGET -H "authorization: bearer $TOKEN" localhost:30000/catalog/items/e0e58243-4138-48e5-8aba-448a8888e2ff | jq .
{
    "item": {
        "id": "e0e58243-4138-48e5-8aba-448a8888e2ff",
        "customer_id": "7c0cde05-4df0-47f4-94c4-978dd9f56e5c",
        "customer_name": "goldie",
        "title": "Mobile Phone",
        "price": "10000"
    }
}

Clean up

make clean

mercari-microservices-example's People

Contributors

110y avatar dependabot[bot] avatar knsh14 avatar moemoe89 avatar oppai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.