Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Breaking down the monolith - devone

Breaking down the monolith - devone

The story of how we broke our Node.js monolith into 20+ services in just a couple of weeks. The talk will focus on what we have learned during the journey and what technologies we use. This is the tale of how we did this rather than what microservices are in general. Attendees are going gain a better understanding on how a microservice architecture effects a company's structure and the daily work. The talk also highlights the key concepts and challenges of the microservice migration with providing practical solutions as well.

https://devone.at/

Peter Marton

June 01, 2017
Tweet

More Decks by Peter Marton

Other Decks in Programming

Transcript

  1. - Helping companies to succeed with Node.js: - Training, Consulting,

    Support - Professional services - Trace: Node.js monitoring and debugging tool
  2. - Why we moved: monolith, microservices - How we moved:

    services, teams and principles - Evolutionary design - Reliability and fault tolerance - Debugging and monitoring Agenda
  3. - Easy to ship, as all the parts move together

    - Easy to create a developer environment - Easy to monitor and debug (we have stack traces) - Perfect for MVP and smaller applications Monolith advantages
  4. - Larger teams work on the same code base -

    Distributed teams can be challenging (in location / time) - Hard to keep a good modular structure - Cannot deploy small changes separately - Cannot scale features separately Monolith drawbacks
  5. - Each element of functionality is a separate service -

    Split by features - Collection of loosely coupled services - Distributed system with remote calls Microservices
  6. - Improves modularity - Smaller scope, easier to understand -

    Smaller codebase: easy to refactor or throw away - Services can be individually designed, developed, tested, and deployed (self-contained) Microservices advantages 1/2
  7. - Services can be scaled separately - Allows technology diversity

    - Can improve reliability - Autonomous teams Microservices advantages 2/2
  8. - Architectural complexity: distributed system - Eventual consistency - Operating

    complexity - Monitoring and debugging complexity - Not the most performant architectural pattern Microservices drawbacks
  9. - Loosely coupled: minimal dependence on other services - High

    cohesion: closely related functionality should stay together - Single bounded context: encapsulates internal details of a domain Don't be misled by the "micro" prefix. “Micro”services
  10. - Avoid distributed transactions - Do not create service until:

    - You don’t understand the domain very well - When it’s not necessary - To prevent multiple data migrations Avoid: distributed monolith
  11. “organizations which design systems ... are constrained to produce designs

    which are copies of the communication structures of these organizations” -  M. Conway Conway’s law
  12. - Cross functional teams - Full range of skills: From

    UX to PM - Each of the teams have: backend, database, ops etc. - Mini products inside the company - Teams ows the full lifecycle Organizing around features
  13. - Distributed teams (different space / time zone) - Smaller

    teams are usually more efficient - More focused and specialized people - Separate smaller releases are possible Possible business reasons to move
  14. - Very different challenges: - time series metrics, distributed tracing

    - Mission critical features: - alerting Our product has:
  15. - We wanted to have focused teams - Develop and

    ship features separately - Segregate failures - Improve reliability We wanted to separate these features
  16. - Highly aligned, loosely coupled teams - Principles helps in

    alignment - Principles should be created together - Teams must follow it Service principles: why?
  17. - Automation is a key in building and operating microservices

    - Setup a new service with CI jobs and monitoring - Easy and fast to deploy and rollback - Testing, Database migration etc. - Reliability automations: auto scaling, rate limiters etc. Service principles: automate everything
  18. - Services should own their data - Separate databases per

    services - Allow polyglot persistence (different database technologies) Service principles: data ownership
  19. - Minimize the depth of the service call-graph - Minimize

    complexity - Increases performance Service principles: complexity
  20. - Only high level utility code pieces - Common libraries

    and frameworks company wide: - High level framework - Libraries for: logging, caching, service communication etc. - Via private npm: scoped packages Service principles: code sharing
  21. - We don’t want to version services - We do

    version endpoints - We create backward compatible endpoints - Use feature flippers / toggles (dark launches) Service principles: versioning
  22. - Interface for other teams - Good and available documentation

    - Update docs and code together Good to start here: https://github.com/Yelp/service-principles Service principles: documentation
  23. - Rewriting your application can be expensive and dangerous -

    Need to ship features in the meantime - Organizational change takes time Evolutionary design: why
  24. - Client(s) specific things: - Authentication: Cookie headers, JWT token

    etc. - Protocols: HTTP, WebSocket etc. - Response format: JSON, XML etc. - Combining resources: from multiple services API Gateway
  25. - We moved from a PaaS - Services were communication

    via public internet - Trusted sources (services) - Request signing between services Security: request signing
  26. - Request signing had significant CPU overhead - Added ~10ms

    to each request - Moved to private networking - One entry point: API Gateway Private networking
  27. - On service level by our communication library - Automatically

    via response headers (with HTTP): - "max-age" and "stale-if-error" - Multi store caching with stale and failover cache - https://github.com/RisingStack/cache Caching
  28. - Services fail separately - Critical resources should be cached

    - Rate limiters and load shedders - Reliability automations: auto scaling, deploy strategies - Architectural patterns and messaging queues can help Fault tolerance
  29. - Fast private network - Quick deploys and rollbacks (with

    immutability) - Zero downtime deployment - Flexible resources, cheap instances Infrastructure: wanted
  30. - Started with PaaS - Good at beginning: rollback, zero

    downtime deployment etc. - Slow and public networking - Expensive and non flexible instance types - Evaluated: more PaaS, AWS EB, Deis (v1) Infrastructure: what we had
  31. - We moved to Kubernetes (GCP managed) - Container orchestration

    (Docker/rkt) - Graceful shutdown - Rolling deployment - Self healing applications - Horizontal autoscaling Infrastructure: Kubernetes
  32. Microservices producing lot’s of data - Logs, Errors - Metrics

    per service - Transactions - Logical connections - Side effects
  33. - Google Dapper white paper - Transaction ID, Correlation ID

    - Commercial: Trace by RisingStack, Dynatrace, AWS X-Ray - OSS: Jaeger, Zipkin - Instrumentation standard: OpenTracing Distributed tracing
  34. - Use private network - Keep your applications close to

    each other - Limit the lengths of service call chains - Cache everything Network delay is evil