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

Modern applications with Serverless

Modern applications with Serverless

Microservice architectures are great but handling infrastructure is not easy. In this deck we will talk about serverless and how this approach simplify our infrastructure.

Mariano Calandra

October 22, 2019
Tweet

More Decks by Mariano Calandra

Other Decks in Technology

Transcript

  1. Modern applications with serverless Mariano Calandra – 1st XPeppers Learning

    Day, 22 Ottobre 2019 Photo by Helloquence on Unsplash
  2. Mariano Calandra Full time developer (mainly .NET + AngularJS) Digital

    payments for PA Enterprise applications Something about me @MarianoCalandra 3 yrs ago
  3. «The critical complexity of the most software projects is in

    understanding the business domain itself.» …a bigger problem ahead
  4. Domain event payment registered A domain event is something that

    has happened in the past. Events flow describe a business scenario.
  5. RegisterPayment DeletePayment VerifyPayment Event storming 11 «…a flexible workshop format

    for collaborative exploration of complex business domains» eventstorming.com
  6. Frontend Payment microservice BI Payment topic BI queue Frontend queue

    Components view When a payment is registered the related event is issued…
  7. Frontend Payment microservice BI Payment topic BI queue Frontend queue

    Components view and it needs to be duplicated (fanout)
  8. Frontend Payment microservice BI Payment topic BI queue Frontend queue

    Components view BI service react to the event doing data analysis Frontend grab the message and prepare the UI
  9. Frontend Payment service BI Payment topic BI queue Frontend queue

    WARN Now the application is modular, but we introduced potential points of failure that needs to be addressed, or…
  10. Frontend Payment service BI Payment topic BI queue Frontend queue

    Introducing Amazon SNS/SQS Simple Notification Service Simple Queue Service Delivery mechanism push pull Messaging type publish/subscribe send/receive Distribution model one-to-many one-to-one
  11. Frontend Payment microservice BI Payment SNS topic BI SQS queue

    Frontend SQS queue Fully managed messaging
  12. Frontend Payment microservice BI Payment SNS topic BI SQS queue

    Frontend SQS queue Business logic What about this component? How can we handle scaling, availability and so on?
  13. Frontend Payment microservice BI Payment SNS topic BI SQS queue

    Frontend SQS queue Introducing AWS Lambda Our microservices can be implemented using a Lambda function…
  14. Payment microservice RegisterPayment DeletePayment Payment topic …or better, our microservice,

    can be implemented as a set of many independent Lambda functions!
  15. RegisterPayment DeletePayment VerifyPayment How it works Functions are sleeping and

    waiting to be invoked Lambda runtime Node.js Go Java C# Ruby Python Powershell Custom runtime
  16. RegisterPayment DeletePayment VerifyPayment How it works When a Lambda function

    is requested, the platform activates it Lambda event source Amazon API Gateway Amazon S3 Amazon DynamoDB Amazon SQS/SNS Amazon CloudWatch Scheduled events ….
  17. RegisterPayment DeletePayment VerifyPayment How it works Once executed, if no

    further requests happens, the Lambda is disposed.
  18. Frontend Payment microservice BI Payment SNS topic BI SQS queue

    Frontend SQS queue Something is still missing What about data?
  19. Frontend Payment microservice BI Payment SNS topic BI SQS queue

    Frontend SQS queue Introducing Amazon DynamoDB Fully managed NoSQL database Multi-master replication Built-in backup/restore Horizontal-scaling Up to 20mln req/sec
  20. Frontend Payment microservice BI Payment SNS topic BI SQS queue

    Frontend SQS queue Payment table Introducing Amazon DynamoDB
  21. Frontend Payment microservice BI Payment SNS topic BI SQS queue

    Frontend SQS queue Payment table Something is still missing… How to fill this table with payment requests?
  22. Payment microservice Payment SNS topic Payment table AWS Transfer For

    SFTP Amazon S3 AWS Step Functions Amason SNS Amazon SQS …first of all We need an ’’inbox’’ for this Payment context.
  23. Payment microservice Payment SNS topic Payment table AWS Transfer For

    SFTP Amazon S3 AWS Step Functions Amason SNS Amazon SQS FTP & CSV
  24. Payment microservice Payment SNS topic Payment table AWS Transfer For

    SFTP Amazon S3 AWS Step Functions Amason SNS Amazon SQS FTP & CSV CSV is uploaded into Amazon S3 bucket.
  25. Payment microservice Payment SNS topic Payment table AWS Transfer For

    SFTP Amazon S3 AWS Step Functions Amason SNS Amazon SQS FTP & CSV Long business process that needs to be orchestrated
  26. Payment microservice Payment SNS topic Payment table AWS Transfer For

    SFTP Amazon S3 AWS Step Functions Amason SNS Amazon SQS AWS Step Functions Workflow orchestration Fully managed Multi-services Error-handling and compensations Workflow monitoring
  27. Payment microservice Payment SNS topic Payment table AWS Transfer For

    SFTP Amazon S3 AWS Step Functions Amason SNS Amazon SQS Process manager RegisterList ValidateList VerifySubscription ImportList AWS Step Functions workflow
  28. Payment microservice Payment SNS topic Payment table AWS Transfer For

    SFTP Amazon S3 AWS Step Functions Amason SNS Amazon SQS Error handling RegisterList ValidateList VerifySubscription ImportList AWS Step Functions workflow CompensateError
  29. Payment microservice Payment SNS topic Payment table AWS Transfer For

    SFTP Amazon S3 AWS Step Functions Amason SNS Amazon SQS FTP & CSV Once completed, notifications are sent to the Amazon SNS topic and pushed out
  30. Payment microservice Payment SNS topic Payment table AWS Transfer For

    SFTP Amazon S3 AWS Step Functions Amason SNS Amazon SQS FTP & CSV This queue will receive the messages and act accordingly
  31. Amazon CloudWatch Metrics const metricData = await cloudWatch.putMetricData({ MetricData: [

    { MetricName: ‘My Custom Metric‘, Dimensions: [ { Name: 'Product’, Value: 'ProductName’ } ], Timestamp: new Date(), Value: 42.0 } ], Namespace: ‘My Namespace' }).promise();
  32. AWS X-Ray const AWSXRay = require('aws-xray-sdk'); const app = express();

    app.use(AWSXRay.express.openSegment('custom-segment’)); // your logic here! app.use(AWSXRay.express.closeSegment());
  33. AWS CodeCommit AWS CodeBuild AWS CloudFormation Template Source Deployed microservice

    AWS CloudFormation ChangeSet Infrastructure as Code Source code and resources’s template are pushed into repository
  34. AWS CodeCommit AWS CodeBuild AWS CloudFormation Template Source Deployed microservice

    AWS CloudFormation ChangeSet Infrastructure as Code 54 Source code is builded and dependencies are installed (e.g. node_modules)
  35. AWS CodeCommit AWS CodeBuild AWS CloudFormation Template Source Deployed microservice

    AWS CloudFormation ChangeSet Infrastructure as Code 55 Generate AWS CloudFormation ChangeSet
  36. AWS CodeCommit AWS CodeBuild AWS CloudFormation Template Source Deployed microservice

    AWS CloudFormation ChangeSet Infrastructure as Code 56 Execute AWS CloudFormation ChangeSet
  37. AWS CodeCommit AWS CodeBuild AWS CloudFormation Template Source Deployed microservice

    AWS CloudFormation ChangeSet Infrastructure as Code 57 You application is up and running
  38. SAM Template AWS CodeCommit AWS CodeBuild AWS CloudFormation Template Source

    Deployed microservice AWS CloudFormation ChangeSet Transform: 'AWS::Serverless-2016-10-31' Resources: ThumbnailFunction: Type: 'AWS::Serverless::Function’ Properties: Runtime: nodejs6.10 Handler: index.handler CodeUri: ./src Events: ThumbnailApi: Type: Api Properties: Path: /thumbnail Method: GET
  39. Progressive deployment AWS CodeCommit AWS CodeBuild AWS CloudFormation Template Source

    Deployed microservice AWS CloudFormation ChangeSet Resources: MyLambdaFunction: Type: AWS::Serverless::Function Properties: # ... DeploymentPreference: Type: Canary10Percent10Minutes Alarms: # A list of alarms that you want to monitor - !Ref AliasErrorMetricGreaterThanZeroAlarm - !Ref LatestVersionErrorMetricGreaterThanZeroAlarm Hooks: # Validation before & after traffic shifting PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction Canary10Percent30Minutes Canary10Percent5Minutes Canary10Percent10Minutes Canary10Percent15Minutes Linear10PercentEvery10Minutes Linear10PercentEvery1Minute Linear10PercentEvery2Minutes Linear10PercentEvery3Minutes AllAtOnce
  40. Takeaways 62 Prefer services over servers Decouple using events Strive

    for observability Avoid big-bang deployments IaC for replication Photo by Clem Onojeghuo on Unsplash