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

Deploying large-scale, serverless and asynchron...

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Deploying large-scale, serverless and asynchronous systems - without integrated tests

Modern distributed architectures are increasingly composed of large numbers of decoupled, asynchronous components. In AWS, these components are plumbed together via services like SQS, SNS, Kinesis and S3 often integrated via small and frequent numbers of microservices or lambdas. But how do you test these architectures if they are cloud native?

It’s 2018, and we can do better than deploying the entire stack and running a battery of E2E tests against them.

In his talk, Matt will demonstrate how you can scale development of large-scale systems across teams, technology and process, and unlock the agility of your cloud-native architecture.

WARNING: there will be code (https://github.com/mefellows/serverless-testing-example)

Avatar for Matt Fellows

Matt Fellows

April 26, 2018

Other Decks in Programming

Transcript

  1. 4 Release Architecture > Evolution More Evolved Time Monolith SOA

    Serverless Microservices Testing Culture Unit tests, TDD, BDD Contract tests Waterfall Outsourcing API Testing Scenario Tests Fn Not all primitives are invisible! Co-evolved practices: XP Agile\Lean Multiple E2E Test Env. Chaos Engineering DevOps CD CI
  2. 5 If you can’t build a good monolith you shouldn’t

    be doing microservices Architecture > Microservices
  3. Entry criteria to make µServices • Ability to write a

    modular monolith • Strong grasp on your domain model • Ability to design loosely coupled services ◦ = state + transactions • Ability to scale and decouple teams • Ability to deploy continuously • A strong “DevOps” culture • Be comfortable with decentralised, complex systems + uncertainty Architecture > Microservices
  4. ...the µServices ride • Ability to write a modular monolith

    • Strong grasp on your domain model • Ability to design loosely coupled services ◦ = state + transactions • Ability to scale and decouple teams • Ability to deploy continuously • A strong “DevOps” culture • Be comfortable with decentralised, complex systems + uncertainty Architecture > Microservices
  5. ...the µServices ride • Ability to write a modular monolith

    • Strong grasp on your domain model • Ability to design loosely coupled services ◦ = state + transactions • Ability to scale and decouple teams • Ability to deploy continuously • A strong “DevOps” culture • Be comfortable with decentralised, complex systems + uncertainty Architecture > Microservices
  6. ...the µServices ride • Ability to write a modular monolith

    • Strong grasp on your domain model • Ability to design loosely coupled services ◦ = state + transactions • Ability to scale and decouple teams • Ability to deploy continuously • A strong “DevOps” culture • Be comfortable with decentralised, complex systems + uncertainty Architecture > Microservices
  7. WHAT WE ARE KNOWN FOR 10 Microservices Evolution Drivers for

    levelling up • Increase time-to-value • Increase utilisation / cost reduction • Raise abstraction; focus on composition • Scale product teams • Massively distributed, real-time apps • API contracts (e.g. OAS) • Ubiquity of cloud computing • Rise of containers • Unreliable networking / components • Rise of the Service Mesh • Improved observability Architecture > Microservices
  8. 18 Much Compose! So speed! Architecture > Functions + Serverless

    (Cloud Native) Architecture > Functions + Serverless (Cloud Native)
  9. 20 If you can’t build good microservices you shouldn’t be

    doing serverless Architecture > Functions + Serverless (Cloud Native)
  10. 21 If you can’t build a good Fn you shouldn’t

    be doing FaaS Architecture > Functions + Serverless (Cloud Native)
  11. 24 Demo: AWS Meetup Lounge CloudFront API Gateway Authentication You!

    awslounge.onegeek.com.au Twitter Fetch Twitter feed Twitter Push IoT Message Broker Sentiment Analysis Checkpoint Amazon ML #awsmelb
  12. WHAT WE ARE KNOWN FOR 28 Options • Multi-cloud =

    lowest common denominator • There is always a vendor (even if it’s you!) • You’ll never be completely vendor agnostic • Multi-cloud abstraction • Avoid altogether • Structure your code better Challenges Challenges > Vendor lock-in
  13. WHAT WE ARE KNOWN FOR 29 Options • Multi-cloud =

    lowest common denominator • There is always a vendor (even if it’s you!) • You’ll never be completely vendor agnostic • Multi-cloud abstraction • Avoid altogether • Structure your code better Challenges Challenges > Vendor lock-in
  14. Lambda Handler Challenges > Vendor lock-in > Lambda Anti-pattern {

    "Records": [ { "EventVersion": "1.0", "EventSubscriptionArn": "somearn", "EventSource": "aws:sns", "Sns": { ... } } ] } { "Success": true }
  15. MQ Handler WebSocket handler MQ Adapter WS Adapter Azure Function

    Adapter Google Cloud Fn Adapter Azure Function Handler Google Cloud Fn Handler Lambda Handler Lambda Adapter Service Repository Adapter (Anti-corruption layer) Ports Business Logic Collaborators ... Challenges > Vendor lock-in > Ports and Adaptors
  16. 32 Challenges > Vendor lock-in > Ports and Adaptors >

    Sentiment Analysis Example Twitter feed Sentiment Analysis IoT Message Broker
  17. Summary Architecture > Microservices • Separate protocol handling from business

    logic • Business logic shouldn’t change with introduction of a new protocol • Port, Adapter and Business Logic are independently testable
  18. WHAT WE ARE KNOWN FOR 38 Options Challenges > Testing

    Locally • Stub services (e.g. Localstack) • Stub API (e.g. Moto) • Multiple handlers • Unit tests
  19. WHAT WE ARE KNOWN FOR 40 Options • Feature arms

    race • Trustworthy? • Integration style = slower • All cloud providers? • Stub services (e.g. Localstack) • Stub API (e.g. Moto) • Multiple handlers • Unit tests Challenges > Testing Locally Challenges
  20. WHAT WE ARE KNOWN FOR 41 Writing good unit tests

    • Follow test pyramid • Stub out AWS APIs • Test your business logic separately from any serverless features (e.g. lambda handler) • Callback pyramid of death • Tests are hard to write • Your business logic knows about AWS • You have to stub multiple services per test • Large methods • Confusing control flow Challenges > Testing Locally > Unit Test Code Smells
  21. 45 Challenges > Testing Locally > Unit Test > Sentiment

    Analysis Example Twitter feed Sentiment Analysis
  22. Summary Architecture > Microservices • Business logic should be tested

    separately from port + adapter • Majority of tests, should be fast unit tests • Stub AWS Services where required • (Lambda) Handlers can be locally integration tested with pre-canned JSON events
  23. WHAT WE ARE KNOWN FOR 50 Options • Local integration

    testing • Cloud env. integration testing • Contract testing Challenges > Async
  24. WHAT WE ARE KNOWN FOR 51 Options • Can’t run

    complete local environment • Many moving parts • Problems with integration testing... • Local integration testing • Cloud env. integration testing • Contract testing Challenges Challenges > Async
  25. WHAT WE ARE KNOWN FOR 52 Options • Can’t run

    complete local environment • Many moving parts • Problems with integration testing... • Local integration testing • Cloud env. integration testing • Contract testing Challenges Challenges > Async
  26. 54 IoT Message Broker Sentiment Analysis Contract { 'Positive': 0.234,

    'Negative': 10.123, 'Neutral': 7.334, 'Mixed': 0 } Consumer Provider Challenges > Async > Contract Tests
  27. 55 CloudFront API Gateway Authentication You! awslounge.onegeek.com.au Twitter Fetch Twitter

    feed Twitter Push IoT Message Broker Sentiment Analysis Checkpoint Amazon ML #awsmelb Challenges > Async > Contract Tests
  28. 56 Authentication Twitter Fetch Twitter feed Twitter Push IoT Message

    Broker Sentiment Analysis Checkpoint #awsmelb Challenges > Async > Contract Tests Contract Contract Contract Contract Contract Contract Contract Contract
  29. WHAT WE ARE KNOWN FOR 57 Problems with automated e2e

    tests • Slow • Easy to break • Hard to fix • Scales badly across teams • Lots of set up \ maintenance • $$ potentially costly Challenges > Async > Contract Tests
  30. WHAT WE ARE KNOWN FOR 59 Test symmetry Solved problems

    New problems • Hard to keep both sides in sync • Fast feedback • Few dependencies • No dedicated environment • Reliable • Easy to debug Challenges > Async > Contract Tests
  31. 68 • Open source • Multiple languages ◦ Javascript ◦

    Go ◦ Python ◦ JVM ◦ .NET ◦ + more pact.io • HTTP contracts • Message contracts
  32. Summary 70 Summary Problems Solutions • Microservices+ • Create cloud

    and protocol anti-corruption layer • Mock out AWS SDK in unit tests • Use contract tests • Reduce reliance on end-to-end environments • Ad-hoc exploratory testing • Serverless complexity > uServices • Testing cloud native services • Avoiding vendor lock-in • Handling asynchronous Fn’s