Sunday, 30 May 2021

Microservices

Microservices are a variant of software dev technique Service-Oriented architecture. 

  • Collection of loosely coupled services
  • Increases modularity
  • Parallelises development
  • Deploy and scale respective services independently
  • Small and responsible for one thing
  • By single domain OR single feature
  •  

Developing a single application as a suite of small services, each running in its own process and communicating with light weight mechanisms, often an http resource api.

Fine grained SOA(Service oriented Architecture)

  • why move to micro services
    • New types of clients - smart phone, tablets, tvs,  watches...
    • controllers designed for web interfaces are not designed for  new clients
    • New persistence technologies
      • We have specialized technologies which offer superior performance for specific use cases
        • Search - Elastic Search
        • Product reviews- can be stored in document store like MongoDB
        • Shopping cart- simple key value store - redis
        • legacy DB

Monolithic  Challenges

  • Single codebase
  • Deployment
  • versioning 
  • team size
  • Feature implementation will be slow due to large code base with large team
  • fixing and deploying defects
  • Advantages
    • easy to comprehend but not to comprehend millions of code
    • single language
  • Disadvanteges
    • Language and framework lock
    • Digesting large code base is difficult. Too many secrets/hacks, 
    • Deploy as single unit

Microservices

  • Small and independent applns built around individual functional areas. Each one uses the backend technologies best suited for its need
  • APi Gateway
    • Various client technlogies need to access our services. Having each client access each service will have issues. So we use api gateway
    • It handles the complexity of talking to services
  • Cloud native architechture
    • Communicate via apis & not common DB
  • Microservices encapsulate business capabilities by business function(cart, catalog, checkout)
    • not based on technology stack - dao, db, 
  • eg: Cart, checkout, REviews, Search
  • Services are not Ochestrated but Choregraphed
  • Challenges
    • Few services may be unavailable
    • Design for failure & curcuit breaker
    • More monitoring required
    • Remote calls expensive than in-process calls
    • Must rely on Eventual Consistency over ACID
    •  Features span multiple services
    • Change management becomes a different challenge
    • Refactoring module boundaries
    • Network
      • should be reliable
      • latency 0
      • bandwidth is infinete
How to break Monolyth into Micro services
  • Primary consideration should be business funcitonality
    • Nouns (Carts, customer, catalog)
    • Verb based(Search, checkout, shipping)
    • single responsibility service
    • Bounded context

SOA vs Microservices

  • SOA is integration of system. Microservices address individual applns
  • soa relies on orchestration, Microservce rely on choregraphy
  • soa is smart integration of dumb services, microserviews is dumb integration of smart services eg: pipes, filters in linux

Spring Cloud

  • Spring cloud config
    • Centralized, externalized, secured, easy to reach source of appl config.
    • application.yml or application.properties to have location where config file is located
    • @EnableConfigServer
  • Spring Cloud bus
    • provides simple way to notify clients about appln config changes
  • Spring cloud netflix Eureka
    • Service discovery- allows applications to register themselves as clients
  • load balancing
  • Circuit breaker
  • zuul
  • cacheing


No comments:

Post a Comment