Serverless Design Patterns and Best Practices

Book description

Get started with designing your serverless application using optimum design patterns and industry standard practices

About This Book
  • Learn the details of popular software patterns and how they are applied to serverless applications
  • Understand key concepts and components in serverless designs
  • Walk away with a thorough understanding of architecting serverless applications
Who This Book Is For

If you're a software architect, engineer, or someone who wants to build serverless applications, which are non-trivial in complexity and scope, then this book is for you. Basic knowledge of programming and serverless computing concepts are assumed.

What You Will Learn
  • Comprehend the popular design patterns currently being used with serverless architectures
  • Understand the various design options and corresponding implementations for serverless web application APIs
  • Learn multiple patterns for data-intensive serverless systems and pipelines, including MapReduce and Lambda Architecture
  • Learn how to leverage hosted databases, queues, streams, storage services, and notification services
  • Understand error handling and system monitoring in a serverless architecture a serverless architecture
  • Learn how to set up a serverless application for continuous integration, continuous delivery, and continuous deployment
In Detail

Serverless applications handle many problems that developers face when running systems and servers. The serverless pay-per-invocation model can also result in drastic cost savings, contributing to its popularity. While it's simple to create a basic serverless application, it's critical to structure your software correctly to ensure it continues to succeed as it grows. Serverless Design Patterns and Best Practices presents patterns that can be adapted to run in a serverless environment. You will learn how to develop applications that are scalable, fault tolerant, and well-tested.

The book begins with an introduction to the different design pattern categories available for serverless applications. You will learn the trade-offs between GraphQL and REST and how they fare regarding overall application design in a serverless ecosystem. The book will also show you how to migrate an existing API to a serverless backend using AWS API Gateway. You will learn how to build event-driven applications using queuing and streaming systems, such as AWS Simple Queuing Service (SQS) and AWS Kinesis. Patterns for data-intensive serverless application are also explained, including the lambda architecture and MapReduce.

This book will equip you with the knowledge and skills you need to develop scalable and resilient serverless applications confidently.

Style and approach

Readers will be taken through a set of specific software patterns and learn, in detail, how to apply these patterns and build working software on top of a serverless system. At each step along the way, the reader will learn about the subcomponents and subsystems which comprise the larger system and which may be used in the future to solve different types of challenges.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Serverless Design Patterns and Best Practices
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  7. Introduction
    1. What is serverless computing?
      1. No servers to manage
      2. Pay-per-invocation billing model
      3. Ability to automatically scale with usage
      4. Built-in availability and fault tolerance
    2. Design patterns
    3. When to use serverless
      1. The sweet spot
    4. Classes of serverless pattern
      1. Three-tier web application patterns
      2. ETL patterns
      3. Big data patterns
      4. Automation and deployment patterns
    5. Serverless frameworks
    6. Summary
  8. A Three-Tier Web Application Using REST
    1. Serverless tooling
    2. System architecture
      1. Presentation layer
      2. Logic layer
      3. Data layer
    3. Logic layer
      1. Application code and function layout
        1. Organization of the Lambda functions
        2. Organization of the application code
      2. Configuration with environment variables
      3. Code structure
      4. Function layout
    4. Presentation layer
      1. File storage with S3
      2. CDN with CloudFront
    5. Data layer
    6. Writing our logic layer
      1. Application entrypoint
      2. Application logic
      3. Wiring handler.py to Lambda via API Gateway
    7. Deploying the REST API
    8. Deploying the Postgres database
    9. Setting up static assets
    10. Viewing the deployed web application
    11. Running tests
    12. Iteration and deployment
      1. Deploying the entire stack
      2. Deploying the application code
    13. Summary
  9. A Three-Tier Web Application Pattern with GraphQL
    1. Introduction to GraphQL
    2. System architecture
    3. Logic layer
      1. Organization of the Lambda functions
      2. Organization of the application code
      3. Function layout
    4. Presentation layer
    5. Writing the logic layer
      1. Implementing the entry point
      2. Implementing GraphQL queries
      3. Implementing GraphQL mutations
    6. Deployment
    7. Viewing the deployed application
    8. Iteration and deployment
    9. Summary
  10. Integrating Legacy APIs with the Proxy Pattern
    1. AWS API Gateway introduction
    2. Simple proxy to a legacy API
      1. Setting up a pass-through proxy
      2. Deploying a pass-through proxy
    3. Transforming responses from a modern API
      1. Method execution flow
      2. Setting up example
      3. Setting up a new resource and method
      4. Setting up Integration Request
      5. Setting up Integration Response
    4. Complex integration using a Lambda function
      1. Implementing the application code
      2. Setting up a new resource and method
    5. Migration techniques
      1. Staged migration
      2. Migrating URLs
    6. Summary
  11. Scaling Out with the Fan-Out Pattern
    1. System architecture
      1. Synchronous versus asynchronous invocation
    2. Resizing images in parallel
      1. Setting up the project
      2. Setting up trigger and worker functions
      3. Setting up permissions
      4. Implementing the application code
      5. Testing our code
    3. Alternate Implementations
      1. Using notifications with subscriptions
      2. Using notifications with queues
    4. Summary
  12. Asynchronous Processing with the Messaging Pattern
    1. Basics of queuing systems
      1. Choosing a queue service
      2. Queues versus streams
    2. Asynchronous processing of Twitter streams
      1. System architecture
      2. Data producer
      3. Mimicking daemon processes with serverless functions
      4. Data consumers
      5. Viewing results
    3. Alternate Implementations
      1. Using the Fan-out and Messaging Patterns together
      2. Using a queue as a rate-limiter
      3. Using a dead-letter queue
    4. Summary
  13. Data Processing Using the Lambda Pattern
    1. Introducing the lambda architecture
      1. Batch layer
      2. Speed layer
    2. Lambda serverless architecture
      1. Streaming data producers
      2. Data storage
      3. Computation in the speed layer
      4. Computation in the batch layer
    3. Processing cryptocurrency prices using lambda architecture
      1. System architecture
        1. Data producer
        2. Speed layer
        3. Batch layer
      2. AWS resources
      3. Data producer
      4. Speed layer
      5. Batch layer
    4. Results
    5. Summary
  14. The MapReduce Pattern
    1. Introduction to MapReduce
      1. MapReduce example
      2. Role of the mapper
      3. Role of the reducer
      4. MapReduce architecture
    2. MapReduce serverless architecture
    3. Processing Enron emails with serverless MapReduce
      1. Driver function
      2. Mapper implementation
      3. Reducer implementation
    4. Understanding the limitations of serverless MapReduce
      1. Memory limits
      2. Storage limits
      3. Time limits
    5. Exploring alternate implementations
      1. AWS Athena
      2. Using a data store for results
      3. Using Elastic MapReduce
    6. Summary
  15. Deployment and CI/CD Patterns
    1. Introduction to CI/CD
      1. CI
      2. CD
    2. Setting up unit tests
      1. Code organization
      2. Setting up unit tests
    3. Setting up CI with CircleCI
      1. Configuring CircleCI builds
      2. Setting up environment variables
    4. Setting up CD and deployments with CircleCI
      1. Setting up Slack notifications
      2. Setting up a CircleCI badge
      3. Setting up deployments
        1. Setting up AWS credentials
        2. Setting up environment variables
      4. Executing deployments
    5. Summary
  16. Error Handling and Best Practices
    1. Error tracking
      1. Integrating Sentry for error tracking
      2. Integrating Rollbar
    2. Logging
      1. Structuring log messages
      2. Digesting structured logs
    3. Cold starts
      1. Keeping cloud functions warm
      2. AWS Lambda functions and VPCs
      3. Start-up times for different languages
      4. Allocating more memory
    4. Local development and testing
      1. Local development
      2. Learning about testing locally
    5. Managing different environments
    6. Securing sensitive configuration
      1. Encrypting variables
      2. Decrypting variables
    7. Trimming AWS Lambda versions
    8. Summary
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Serverless Design Patterns and Best Practices
  • Author(s): Brian Zambrano
  • Release date: April 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788620642