Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MicroServices - How Do I Build Them - DundeePHP August 2016

MicroServices - How Do I Build Them - DundeePHP August 2016

A lightning overview and how some handy tips I've learned for building services locally

Scott Pringle

August 25, 2016
Tweet

More Decks by Scott Pringle

Other Decks in Programming

Transcript

  1. What are they? Software design architecture of separating an application

    into a suite of small, independent services. Independent applications with no dependencies on any other services. Exposed via a pre-defined API for external consumers
  2. Smaller Apps & Teams • The less your app has

    to do, the less complex it (should) be • Easier to understand the purpose of the code • Separate teams based on service boundaries • Manage knowledge within teams easier • Designate internal leaders to manage workflow
  3. Testability • The more defined your context is, the easier

    it is to test • Test suite will be smaller and quicker to run • Unit and Integration tests are fast - use them
  4. Polyglotism • Every service can be written in any language

    • Use the tools that are right for the job • Can result in complex systems with too much variation - Proceed with caution
  5. Redundancy • Both an advantage and disadvantage • Consumers need

    to be redundant to handle a service not working • Should result in better uptime for customer-facing applications
  6. Cross Service Transactions Avoid, avoid, avoid If one part fails,

    how do you roll back everything? Use queues (RabbitMQ/SQS) and dispatch events
  7. Eventual Consistency Data can’t be expected to be permanently consistent

    across services Read models may be updated from multiple sources
  8. Service Discovery • Extremely frustrating • Services need to be

    load balanced • Can’t expose specific ports for a service
  9. Harder to test Might seem strange as earlier I mentioned

    they’re easier to test Unit tests are easier as you know the boundaries of each individual service and it’s collaborators Functional tests are nearly impossible
  10. Reporting Push all data to one central store used ONLY

    for reporting • Redshift • Google BigQuery Do not use this data for transactional information Automatically updated views/queries for reporting
  11. CQRS To The Rescue • Have as many read models

    as your system requires • Build domain logic to handle commands/writes • Reads interact directly with the data-store • Use whatever data-store makes sense for the read model
  12. Problems... • Machines only have a certain amount of memory

    • Don’t want to checkout 50+ services to run 1 application
  13. Being Selective • Only run the services you actually need

    to test • You’re only going to be add/updating 1 or 2 parts of the system, run those services
  14. Shared Resources • Only do this for development… • No

    need to run 15 MySQL Containers/Instances on a local machine
  15. Application SDKs • Provide an SDK for every language /

    framework being employed to build an application • Expose your MicroService API via methods • Only need to update the SDK • Provide Mock data for development