Giter VIP home page Giter VIP logo

mini-microservice's Introduction

mini-microservice

Building a simple post-and-comment project using microservice concept

Goals of this Project 🎯

  1. Get a taste of a microservice architecture (async, event-based communication between services)
  2. Build as much as possible from scratch
  3. Get a basic understanding of how to communicate between front-end and back-end

Disclaimer ⚠️

Do not use this project as a template for future microservices stuff.
see why

System Overview 🌐

This application provides a simple post-and-comment functionality that users can create a new post and enter a comment to that post.
Each comment will be moderated from the system whether that comment should be displayed or not.

The following are the main components (services) of the system:

  • Client: A typical Front-end application making a request to query service to display post and comment.
  • Post: A service used to CREATE and GET posts.
  • Comment: A service used to CREATE and GET comments including receiving updated comment from moderation service.
  • Moderation: A service used to handle 'created' comments and apply some text moderation to it whether that comment should be approved or rejected.
  • Query: A service used to serve and sync all the data to the client. This service is a replacement for GET posts and comments in order to minimize making lots of requests by the client.
  • Event Bus: Receives events and publishes them to all of the services.

Side Note: Each service is contained inside a docker image which will be deployed inside a kubernetes pod (one container per pod) which is exposed by a Cluster IP service.

Tech Stack 🧰

  • Front-end: React
  • Back-end: Express.js, node.js
  • Database: Local machine (literally)
  • Devops: Docker, Kubernetes, ingress-nginx, skaffold
  • Programming Languange: Javascript
  • Tools: Postman, VS Code
  • Package Manager: npm, choco

API Reference 🧭

Get all posts and comments

  GET /posts

Add post

  POST /posts/create
Parameter Type Description
title string title or topic of the post

Add comment

  POST /posts/:id/comments
Parameter Type Description
id string id of the post
content string comment message

Containerization 🐳

Create a single lightweight executable—called a container—that runs consistently on any infrastructure using Docker

# in each service directory
# build a docker image
docker build -t username/imagename:tagname .

# create and start a docker container from the image
docker run username/imagename:tagname

# push the image to docker hub
docker push username/imagename:tagname

Container Orchestration 🏗️

Managing all of the services inside containers i.e. deployment, networking with services and ingress using kubernetes and ingress-nginx

# inside infra/k8s directory
# creating pods, deployments and services 
kubectl apply -f service-depl.yaml

# exposes HTTP routes from outside the cluster to services within the cluster.
kubectl apply -f ingress-srv.yaml

# manually restart deployments after making some changes in an image
kubectl rollout restart deployment service-depl

Continuous Development 🔁

Automactically handling the workflow for building, pushing, and deploying services using skaffold

# inside the base directory where skaffold.yaml is
# do a full build and deploy of all artifacts specified in the skaffold.yaml
skaffold dev

# cleanup all the artifacts (if ctrl + c doesn't work)
skaffold delete

Lesson Learned 📚

@omekrit's opinion

  • The big challenge in microservice is data since each service has its own database.
  • Async communication focuses on communicating changes using events sent to an event bus.
  • Async communication encourages each service to be 100% self-sufficient which will be relatively easy to handle temporary downtime or new service creation.
  • Docker makes it easier to package up services.
  • Kubernetes is a pain to setup, but makes it easier to deploy and scale services.
  • Apart of microservice concept, it's a prerequisite for everyone before jumping into the microservice world to first have a basic understanding of how to build an app (programming languages, front-end, back-end, frameworks, tools, and other stuff related)

Downside of this App 👎

  • Lots of duplicated code (specifically the backend services).
  • It's a pain to picture and test the flow of events between services.
  • It's also a pain to remember what properties an event should have.
  • Running kubernetes locally is not a good idea (laggy).

mini-microservice's People

Contributors

khomkrity avatar

Watchers

 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.