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.

Reactive Microservices with AWS Lambda (SRV201-R1) - AWS re:Invent 2018

523 views

Published on

In this talk, we cover the concepts of reactive microservices architecture, a set of patterns and best practices for implementing backend systems with very high scaling and availability guarantees. We show you how to implement these patterns and best practices as serverless applications using AWS technologies like AWS Lambda, Amazon API Gateway, Amazon DynamoDB, and Amazon Kinesis. In addition, we demonstrate a serverless microservice and the pitfalls to consider when running these microservices in a production environment.

  • Be the first to comment

Reactive Microservices with AWS Lambda (SRV201-R1) - AWS re:Invent 2018

  1. 1. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Reactive Microservices with AWS Lambda Lu Hong Software Development Engineer AWS Serverless Apps S R V 2 0 1
  2. 2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What is serverless? https://aws.amazon.com/serverless/
  3. 3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. More than just AWS Lambda! https://aws.amazon.com/serverless/
  4. 4. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What are reactive microservices? https://aws.amazon.com/serverless/
  5. 5. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Example: Simple banking microservice
  6. 6. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Here are our tools for today
  7. 7. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless API POST /accounts GET /accounts/{accountId}
  8. 8. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  9. 9. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Traditional data access accountId customerId type balance 1 A CHECKING $25.00 2 B SAVINGS $40.00 3 A SAVINGS $10.00 4 C CHECKING $35.00
  10. 10. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Traditional data access accountId customerId type balance 1 A CHECKING $25.00 2 B SAVINGS $40.00 3 A SAVINGS $10.00 4 C CHECKING $35.00 Account account = getAccountById(1) account.credit($25.00)
  11. 11. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Traditional data access accountId customerId type balance 1 A CHECKING $25.00 2 B SAVINGS $40.00 3 A SAVINGS $10.00 4 C CHECKING $35.00 accountId customerId type balance 1 A CHECKING $50.00 2 B SAVINGS $40.00 3 A SAVINGS $10.00 4 C CHECKING $35.00 Account account = getAccountById(1) account.credit($25.00)
  12. 12. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Event sourcing sequence event 1 CREATED: {customerId:A, type:CHECKING, initialBalance:$25.00} 2 CREDITED: {amount:$25.00, creditType:DEPOSIT, refId:12345} 3 DEBITED: {amount:$10.00, debitType:WITHDRAWAL, refId:54321} accountId: 1
  13. 13. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Event sourcing sequence event 1 CREATED: {customerId:A, type:CHECKING, initialBalance:$25.00} 2 CREDITED: {amount:$25.00, creditType:DEPOSIT, refId:12345} 3 DEBITED: {amount:$10.00, debitType:WITHDRAWAL, refId:54321} 4 DEBITED: {amount:$20.00, debitType:FEE, refId:6789} accountId: 1
  14. 14. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  15. 15. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CQRS Traditional Command operations Query operations Command operations Query operations CQRS
  16. 16. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Write operations Amazon DynamoDB Streams + Lambda Event store Query view Non-primary key query operations Consumer Lambda
  17. 17. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless CQRS Event store Query view GetAccountsByCustomer Consumer Lambda Write operations + GetAccountById
  18. 18. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  19. 19. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  20. 20. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  21. 21. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Single entity, many log entries accountId sequence event 1 1 CREATED: {customerId:A, type:CHECKING, initialBalance:$25.00} 1 2 CREDITED: {amount:$25.00, creditType:DEPOSIT, refId:12345} 1 3 DEBITED: {amount:$10.00, debitType:WITHDRAWAL, refId:54321} 1 4 DEBITED: {amount:$20.00, debitType:FEE, refId:6789} … … … 1 536 CREDITED: {amount:$30.00, creditType:DEPOSIT, refId:5435} 1 537 DEBITED: {amount:$20.00, debitType:WITHDRAWAL, refId:1290}
  22. 22. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Solution: Snapshots accountId version snapshot 1 512 {customerId:A, type:CHECKING, balance:$220.00} 1 536 {customerId:A, type:CHECKING, balance:$135.00}
  23. 23. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Solution: Snapshots accountId sequence event 1 1 CREATED: {customerId:A, type:CHECKING, initialBalance:$25.00} 1 2 CREDITED: {amount:$25.00, creditType:DEPOSIT, refId:12345} 1 3 DEBITED: {amount:$10.00, debitType:WITHDRAWAL, refId:54321} 1 4 DEBITED: {amount:$20.00, debitType:FEE, refId:6789} … … … 1 536 CREDITED: {amount:$30.00, creditType:DEPOSIT, refId:5435} 1 537 DEBITED: {amount:$20.00, debitType:WITHDRAWAL, refId:1290} accountId version snapshot 1 512 {customerId:A, type:CHECKING, balance:$220.00} 1 536 {customerId:A, type:CHECKING, balance:$135.00}
  24. 24. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  25. 25. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Event sourcing: Optimistic locking accountId sequence event 1 1 CREATED: {customerId:A, type:CHECKING, initialBalance:$25.00} 1 2 CREDITED: {amount:$25.00, creditType:DEPOSIT, refId:12345} 1 3 DEBITED: {amount:$10.00, debitType:WITHDRAWAL, refId:54321} sequence: 4 event: DEBITED: {amount:$20.00, debitType:FEE, refId:6789 sequence: 4 event: DEBITED: {amount:$40.00, debitType:WITHDRAWAL, refId:141
  26. 26. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Event sourcing: Optimistic locking accountId sequence event 1 1 CREATED: {customerId:A, type:CHECKING, initialBalance:$25.00} 1 2 CREDITED: {amount:$25.00, creditType:DEPOSIT, refId:12345} 1 3 DEBITED: {amount:$10.00, debitType:WITHDRAWAL, refId:54321} sequence: 4 event: DEBITED: {amount:$20.00, debitType:FEE, refId:6789 sequence: 4 event: DEBITED: {amount:$40.00, debitType:WITHDRAWAL, refId:141 OptimisticLockException
  27. 27. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Optimistic locking with DynamoDB aws dynamodb put-item --table-name BankAccountEntityEvents --condition-expression “attribute_not_exists(EntityId) AND attribute_not_exists(SequenceNumber)” ...
  28. 28. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  29. 29. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Launched in preview @ re:Invent 2017
  30. 30. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Generally available in February 2018
  31. 31. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Consuming applications Lambda Console AWS SDK Serverless Application RepositorySearch/deploy SAM apps Consumers (AWS customers)
  32. 32. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Consuming applications
  33. 33. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Consuming applications
  34. 34. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Consuming applications
  35. 35. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Publishing applications Publisher Console AWS SDK Serverless Application Repository Publish SAM apps Publishers (AWS customers)
  36. 36. Thank you! © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Thank you! © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lu Hong Twitter: @luhong07
  37. 37. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

×