Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Design Microservice Architectures the Right Way

2,347 views

Published on

Learn from first hand, deep experience, the most critical decisions we face in building successful microservice architectures: how to think about the tradeoffs that impact the productivity of our teams and the quality of our software. In particular, understand how to avoid creating an architecture that eventually (and sometimes quickly) paralyzes our ability to execute. This talk highlights specific key decisions that very directly impact the quality and maintainability of a micro service architecture, covering infrastructure, continuous deployment, communication, event streaming, language choice and more, all to ensure that our teams and systems remain productive as we scale.

Published in: Software

Design Microservice Architectures the Right Way

  1. 1. Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io / @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO Gilt
  2. 2. A personal story Could you change this URL from https://foo.com/latest/bar.js to https://foo.com/1.5.3/ bar.js ? è Sorry – that would take weeks; we don’t have the resources to do that.
  3. 3. https://www.pinterest.com/pin/262264378280617506/ It’s just a friggin URL!!!
  4. 4. How does this happen? • URL in a library • 100s of services to update • Some not touched in years, requiring dependency updates https://www.pinterest.com/pin/262264378280617506/
  5. 5. Great Architecture Scales Development Teams Delivers Quality Enables High Performance / Low Cost Supports Future Features Naturally
  6. 6. Not So Great Architecture Tradeoffs: http://ziogeek.com/wp-content/uploads/2013/07/spaghetti.jpg Near term velocity Future Paralysis
  7. 7. Design Micro Service Architectures the Right Way
  8. 8. About Me www.flow.io www.gilt.com
  9. 9. Let’s Start With a few Misconceptions
  10. 10. Misconception #1 Micro Services enable our teams to choose the best programming languages and frameworks for their tasks Reality: We’ll demonstrate just how expensive this is. Team size and investment are critical inputs.
  11. 11. Misconception #2 Code Generation is Evil Reality: What’s important is creating a defined schema that is 100% trusted. We’ll demonstrate one technique leveraging code generation
  12. 12. Misconception #3 The Event Log Must be the Source of Truth Reality: Events are critical parts of an interface. But it’s okay for services to be the system of record for their resources.
  13. 13. Misconception #4 Developers can maintain no more than 3 services each Reality: Wrong metric; we’ll demonstrate where automation shines. Flow developers today each maintain ~5 services Weekly maintenance <5% of time
  14. 14. Flow Commerce Architecture Flow Platform ArchitectureExternalDataProviders (e.g.,FX,IPGeo,IIN/BIN,etc.) Catalog Payment Inventory Orders 100+ services Event Bus (Kinesis) Lambda Architecture / Data Mart API Proxy OMS 3PL / WMS, Etc. Ecommerce Platform Retail Website FLOW APIs Flow.js Flow Console Track.flow.io Microservices Integration Methods & Services Client Platform Fulfillment Shopify Magento SFCC Solidus Plugins & Cartridges Direct Integrations Checkout UI Flow System Client System 3rd Party Data Data Flow Key FTP Webhook Kinesis Partner API Amazon Web Services Client Checkout
  15. 15. API Definition Done correctly, even things like GDPR compliance can be modeled
  16. 16. Resource Oriented
  17. 17. Definitions in Git, with Continuous Integration
  18. 18. Tests Enforce Consistency Goal: It should feel like one person wrote the entire API
  19. 19. Tests Prevent Errors https://app.apibuilder.io/history?org=flow&app=api Verify potentially breaking changes during API Design Phase
  20. 20. API Implementation Supported by Code Generation
  21. 21. Code Generation: Routes Guarantee that API operations are actually defined User friendly paths Consistent naming for methods
  22. 22. Code Generation: Client
  23. 23. Code Generation: Mock Client Mock and Client from Same Source Enables High Fidelity, Fast Testing
  24. 24. Code Generation: Clients The system of record IS the API specification Code generation ensures that we actually adhere to the spec Provide many common languages for our users [https://app.apibuilder.io/generators/]
  25. 25. Now Let’s Implement Goal: Code we actually write is simple, consistent
  26. 26. Database Architecture Each micro service application owns its database No other service is allowed to connect to the database Other services use only the service interface (API + Events)
  27. 27. Create a Database CLI as single interface for infra and common development tasks
  28. 28. Define storage requirements in metadata Describe ”scala” requirements Describe “psql” requirements Code generate the table definition Code generate the Data Access Object Note data tier independent from API, Just uses same toolchain
  29. 29. Code generation: Create a Table Consistent checks, metadata Enable global features like ‘hash_code’ to minimize writes
  30. 30. Code generation: Scala Class Normalize access to DB Ensure proper indexes exist from start
  31. 31. Automated Tests Use the generated mock client
  32. 32. Test Resource Operations Use the generated mock clients to write simple tests
  33. 33. Time to Deploy
  34. 34. Continuous Delivery “Continuous Delivery is a prerequisite to managing micro service architectures” --@mbryzek
  35. 35. Continuous Delivery Deploy triggered by a git tag Git tags created automatically by a change on master (e.g. merge PR) 100% automated, 100% reliable
  36. 36. Continuous Delivery is Critical https://github.com/flowcommerce/delta
  37. 37. Auto Deploy on New Commit on Master
  38. 38. Microservice Infrastructure – keep it simple
  39. 39. Standard Health Checks
  40. 40. Events
  41. 41. “We have an amazing API, but please subscribe to our event streams instead.”
  42. 42. Principles of an Event Interface First class schema for all events Producers guarantee at least once delivery Consumers implement idempotency Flow: - End to end single event latency ~ 500 ms - Based on postgresql – scaled to ~1B events / day / service
  43. 43. Events: Approach Producers: • Create a journal of ALL operations on table • Record operation (insert, update, delete) • On creation, queue the journal record to be published • Real time, async, we publish 1 event per journal record • Enable replay by simply requeuing journal record
  44. 44. Events: Approach Consumers: • Store new events in local database, partitioned for fast removal • On event arrival, queue record to be consumed • Process incoming events in micro batches (by default every 250ms) • Record failures locally
  45. 45. Events: Schema First 1 model / event N events in one union type 1 union type / stream Stream owned by 1 service Most services define exactly 1 stream
  46. 46. Events: Schema Linter
  47. 47. Producers: Database Journal Document retention period Code generate journal Use partitions to manage storage https://github.com/gilt/db-journaling
  48. 48. Producers: Streams Reflection used to generate stream name io.flow.v0.user_event.json
  49. 49. Producing an Event Note the UserVersion class which is also code generated. Guarantees that all code in all services looks the same.
  50. 50. Producers: Testing
  51. 51. Consumers: Processing Incoming Events
  52. 52. Consumers: Testing Factories classes generated from the API Spec
  53. 53. Dependencies Keeping things up to date
  54. 54. Dependencies Goal: Automatically update all services to latest dependencies • Critical for security patches / bug fixes in core libraries • Takes hours (not weeks or months) • Same process for internally developed libraries and open source • Flow: we upgrade all services every week to latest dependencies
  55. 55. Dependencies: Tracking https://dependency.flow.io/ https://github.com/flowcommerce/dependency
  56. 56. Dependencies: Updating
  57. 57. Dependencies & Continuous Delivery Deploy Once the Build Passes
  58. 58. Summary: Critical Decisions Design schema first for all APIs and Events – consume events (not API) by default Invest in automation – deployment, code generation, dependency management Enable teams to write amazing and simple tests – drives quality, streamlines maintenance, enables continuous delivery
  59. 59. Thank You! Go forth and Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io / @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO Gilt We’re hiring: https://www.flow.io/careers

×