Thanks to visit codestin.com
Credit goes to github.com

Skip to content

nuthanc/microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

544 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microservices with Node JS and React

What is a Microservice

Data in Microservices

  • D 13-db:
  • D 14-db:
  • D 16-why:
  • D 15-db: Separate db for each service
  • D 16-db: Not to access data
  • D 17-why:
  • D 18-why: DB-per-service
    • D 19-c:
    • D 18-te:
    • D 19-st:
    • D 20-st:

Big Problems with Data

  • D 14-db:
  • D 4-c:
  • D 5-c: App
  • D 8-fe, 9-m, 10-new: Monolithic Approach
  • D 11-ms, 12-new: Microservices Approach
    • How Service D will access data as in microservices we don't touch other services db

Sync Communication between Services

Event-Based Communication

  • Asynchronous communication introduces Event Bus which is accessible from all the different services
  • D 12-event:
    • Each service can emit events(notifications or objects) to or receive events from the Event Bus
    • Single point of failure but we make it very resilient
  • D 13-events:
    • Service D emits an event to the Event Bus
    • Event Bus sends it to Service A
    • Service A emits another event to Event Bus responding to the received event
    • Event Bus to Service D
  • D 5-down: Same downsides with Sync along with additional Downsides
    • Replace Request with Events

A Crazy Way of Storing Data

  • D 8-async:
  • D 1-data:
  • D 9-async:
  • D 10-refine:
  • D 11-db: Table containing only required Fields or Columns
    • Question is how to create the db and stick in the relevant info
  • D 12-reqs: Hard to get info to the db as the info is not directly communicated to Service D
  • D 12-async:
    • Request to Create a Product to Service B
    • Service B updates its DB along with simultaneously emitting an event to Event Bus or Broker
    • Event Bus sends that to interested services, service D in our case
    • Service D will record that event in its db
    • Similarly the same process with Service A and Service C, which gets communicated to interested services via the Event Bus

Pros and Cons of Async Communication

  • D 13-async:
    • D 10-refine: Not 100% duplication due to this Requirement Refinement
    • D 14-pricing: Price is not a cause for concern

App Overview

Project Setup

  • D 6-tech: No db this time
  • D 7-steps:
  • mkdir blog
  • Rest of README in blog dir

React Project Setup

Lessons from App#1

Big Ticket Items

App Overview

  • stubhub.com
  • D 6-tick: Ticketing App
  • D 5-browser: Mockups

Resource Types

  • D 7-resources:
  • Order object is the intent to purchase the ticket(When clicked on Purchase button)

Service Types

  • D 8-services:
  • D 9-note: Not necessary to have a separate service for each type of Resource
    • Ticket and Order can be one service
    • Payment and Expiraton can be one service
    • It really depends on the Applications how tightly or loosely coupled they are

Events and Architecture Design

  • D 10-events:
  • D 11-design:
    • common is a npm module which acts as Shared library
    • Event bus: NATS Streaming Server

Auth Service Setup

  • D 12-auth:
  • mkdir ticketing and cd into it

Leveraging a Cloud Environment for Development

Note on Remote Development

Remote Dev with Skaffold

  • D 2-local:
  • D 3-remote, 4-sk
  • D 5-sk: Unsynced file rebuild the image(E.g: package.json)

Google Cloud Initial Setup

  • cloud.google.com/free
  • Click on Go to Console
  • Create New Project

Kubernetes Cluster Creation

  • Go to Kubernetes Engine from the Sidebar
  • Select Clusters and Create Cluster
    • Change the Name according to your requirements
    • Select the zone which is closer to you
    • At least 1.15 k8s master version Static version
  • Go to Node pools on the Sidebar
    • Size: no. of nodes
    • Nodes
      • Machine type: g1-small
  • Create on the bottom left hand side

Kubectl Contexts

  • D 9-context: Context are connection settings like auth credentials, users, ip addresses etc
  • Install Google Cloud SDK: cloud.google.com/sdk/docs/quickstarts
  • Do every installations execpet Initialize the SDK

Initialzing the GCloud SDK

gcloud
# The above for checking 
gcloud auth login
gcloud init
# Select the account
# Select the project, if you don't find your project Go to console in browser and check the id for your project
# Yes for Compute region and select the region you selected for the k8s cluster

Installing the GCloud Context

  • D 10-options:
    • Cluster name is whatever was entered in k8s clusters in Console
# ex for with Docker
gcloud container clusters get-credentials ticketing-dev
# Check for additional entry in Context of Docker for Mac Kubernetes Option

Updating the Skaffold Config

  • D 7-process:
  • Go to Google Cloud Console and select Cloud Build and click on Enable
  • Check on skaffold.yaml in the root dir of microservice for the Google cloud changes
  • Changes in build key(googleCloudBuild)

More Skaffold Updates

  • D 7-process:
  • Comment local push
  • Check the image name in the deployment files

Creating a Load Balancer

Final Config and Test

  • D 7-process:
  • With correct context selected, run
skaffold dev
# In root project dir, e.g ticketing
# Check build process in Cloud Build of Google Cloud console
# History in Cloud Build
  • Changes for remote dev
    • skaffold.yaml googleCloudBuild, image
    • Deployment files image
  • Delete the cluster if you are not using

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •