Discover millions of ebooks, audiobooks, and so much more with a free trial

From $11.99/month after trial. Cancel anytime.

Serverless Architectures on AWS, Second Edition
Serverless Architectures on AWS, Second Edition
Serverless Architectures on AWS, Second Edition
Ebook538 pages4 hours

Serverless Architectures on AWS, Second Edition

Rating: 5 out of 5 stars

5/5

()

Read preview

About this ebook

Design low-maintenance systems using pre-built cloud services! Bring down costs, automate time-consuming ops tasks, and scale on demand.

In Serverless Architectures on AWS, Second Edition you will learn:

    First steps with serverless computing
    The principles of serverless design
    Important patterns and architectures
    How successfully companies have implemented serverless
    Real-world architectures and their tradeoffs

Serverless Architectures on AWS, Second Edition teaches you how to design serverless systems. You’ll discover the principles behind serverless architectures, and explore real-world case studies where companies used serverless architectures for their products. You won’t just master the technical essentials—the book contains extensive coverage of balancing tradeoffs and making essential technical decisions. This new edition has been fully updated with new chapters covering current best practice, example architectures, and full coverage of the latest changes to AWS.

About the technology
Maintaining server hardware and software can cost a lot of time and money. Unlike traditional data center infrastructure, serverless architectures offload core tasks like data storage and hardware management to pre-built cloud services. Better yet, you can combine your own custom AWS Lambda functions with other serverless services to create features that automatically start and scale on demand, reduce hosting cost, and simplify maintenance.

About the book
In Serverless Architectures with AWS, Second Edition you’ll learn how to design serverless systems using Lambda and other services on the AWS platform. You’ll explore event-driven computing and discover how others have used serverless designs successfully. This new edition offers real-world use cases and practical insights from several large-scale serverless systems. Chapters on innovative serverless design patterns and architectures will help you become a complete cloud professional.

What's inside

    First steps with serverless computing
    The principles of serverless design
    Important patterns and architectures
    Real-world architectures and their tradeoffs

About the reader
For server-side and full-stack software developers.

About the author
Peter Sbarski is VP of Education and Research at A Cloud Guru. Yan Cui is an independent AWS consultant and educator. Ajay Nair is one of the founding members of the AWS Lambda team.

Table of Contents
PART 1 FIRST STEPS
1 Going serverless
2 First steps to serverless
3 Architectures and patterns
PART 2 USE CASES
4 Yubl: Architecture highlights, lessons learned
5 A Cloud Guru: Architecture highlights, lessons learned
6 Yle: Architecture highlights, lessons learned
PART 3 PRACTICUM
7 Building a scheduling service for ad hoc tasks
8 Architecting serverless parallel computing
9 Code Developer University
PART 4 THE FUTURE
10 Blackbelt Lambda
11 Emerging practices
LanguageEnglish
PublisherManning
Release dateApr 12, 2022
ISBN9781638354024
Serverless Architectures on AWS, Second Edition
Author

Peter Sbarski

Dr. Peter Sbarski is a well-known AWS expert, VP of engineering at A Cloud Guru, and head of Serverlessconf.

Related to Serverless Architectures on AWS, Second Edition

Related ebooks

Databases For You

View More

Related articles

Reviews for Serverless Architectures on AWS, Second Edition

Rating: 5 out of 5 stars
5/5

1 rating1 review

What did you think?

Tap to rate

Review must be at least 10 words

  • Rating: 5 out of 5 stars
    5/5
    great book, must read for learning AWS serverless from basics to advanced

Book preview

Serverless Architectures on AWS, Second Edition - Peter Sbarski

praise for the first edition

A comprehensive, clear and very practical guide to making the best use of AWS throughout an application’s lifecycle. Highly recommended for anyone wanting to use AWS for real-life applications!

—Alain Couniot, Head of Enterprise Architecture, STIB-MIVB, Belgium

Peter’s tome not only dives deep on Lambda, it also covers all the AWS components your apps will need to run serverless. A soup-to-nuts tour de force. Well done!

—Sean Hull, Founder, iHeavy, Inc.

A great introduction for those using AWS, who want to implement a serverless architecture.

—John Huffman, Senior Technical Consultant, Summa Technologies

This book is a fantastic introduction to serverless architectures and AWS. I wish every technical book was as well written and easy to read! The book walks you step-by-step through building a video portal, including integrating AWS Lambda, API Gateway, S3, auth0 and Firebase. By the end you feel confident not only that you understand all the pieces and how everything fits together, but also that you are ready to start building your own app.

—Kent R. Spillner, Sr. Software Engineer, DRW

Serverless Architectures on AWS, Second Edition

Peter Sbarski, Yan Cui, Ajay Nair

To comment go to liveBook

Manning_M_small

Manning

Shelter Island

For more information on this and other Manning titles go to

www.manning.com

Copyright

For online information and ordering of these and other Manning books, please visit www.manning.com. The publisher offers discounts on these books when ordered in quantity.

For more information, please contact

Special Sales Department

Manning Publications Co.

20 Baldwin Road

PO Box 761

Shelter Island, NY 11964

Email: [email protected]

©2022 by Manning Publications Co. All rights reserved.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.

♾ Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine.

ISBN: 9781617295423

dedication

To my mum and dad, who always supported and encouraged my passion for computing.

—Peter Sbarski

To my wife, who always supports and encourages me, and puts up with all my late-night coding sessions.

—Yan Cui

To my wife, my kids, my brother, and my parents, thank you for giving me the purpose and time to do this.

—Ajay Nair

contents

preface

acknowledgments

about this book

about the authors

about the cover illustration

Part 1 First steps

1 Going serverless

1.1 What’s in a name?

1.2 Understanding serverless architectures

Service-oriented architecture and microservices

Implementing architecture the conventional way

Implementing architecture the serverless way

1.3 Making the call to go serverless

1.4 Serverless pros and cons

1.5 What’s new in this second edition?

2 First steps to serverless

2.1 Building a video-encoding pipeline

A quick note on AWS costs

Using Amazon Web Services (AWS)

2.2 Preparing your system

Setting up your system

Working with Identity and Access Management (IAM)

Let’s make a bucket

Creating an IAM role

Using AWS Elemental MediaConvert

Using MediaConvert Role

2.3 Starting with the Serverless Framework

Setting up the Serverless Framework

Bringing Serverless Framework to The 24-Hour Video

Creating your first Lambda function

2.4 Testing in AWS

2.5 Looking at logs

3 Architectures and patterns

3.1 Use cases

Backend compute

Internet of Things (IoT)

Data processing and manipulation

Real-time analytics

Legacy API proxy

Scheduled services

Bots and skills

Hybrids

3.2 Patterns

GraphQL

Command pattern

Messaging pattern

Priority queue pattern

Fan-out pattern

Compute as glue

Pipes and filters pattern

Part 2 Use cases

4 Yubl: Architecture highlights, lessons learned

4.1 The original Yubl architecture

Scalability problems

Performance problems

Long feature delivery cycles

Why serverless?

4.2 The new serverless Yubl architecture

Rearchitecting and rewriting

The new search API

4.3 Migrating to new microservices gracefully

5 A Cloud Guru: Architecture highlights, lessons learned

5.1 The original architecture

The journey to 43 microservices

What is GraphQL

Moving to GraphQL

Service discovery

Security in the BFF world

5.2 Remnants of the legacy

6 Yle: Architecture highlights, lessons learned

6.1 Ingesting events at scale with Fargate

Cost considerations

Performance considerations

6.2 Processing events in real-time

Kinesis Data Streams

SQS dead-letter queue (DLQ)

The Router Lambda function

Kinesis Data Firehose

Kinesis Data Analytics

Putting it altogether

6.3 Lessons learned

Know your service limits

Build with failure in mind

Batching is good for cost and efficiency

Cost estimation is tricky

Part 3 Practicum

7 Building a scheduling service for ad hoc tasks

7.1 Defining nonfunctional requirements

7.2 Cron job with EventBridge

Your scores

Our scores

Tweaking the solution

Final thoughts

7.3 DynamoDB TTL

Your scores

Our scores

Final thoughts

7.4 Step Functions

Your scores

Our scores

Tweaking the solution

Final thoughts

7.5 SQS

Your scores

Our scores

Final thoughts

7.6 Combining DynamoDB TTL with SQS

Your scores

Our scores

Final thoughts

7.7 Choosing the right solution for your application

7.8 The applications

Your weights

Our weights

Scoring the solutions for each application

8 Architecting serverless parallel computing

8.1 Introduction to MapReduce

How to transcode a video

Architecture overview

8.2 Architecture deep dive

Maintaining state

Step Functions

8.3 An alternative architecture

9 Code Developer University

9.1 Solution overview

Requirements listed

Solution architecture

9.2 The Code Scoring Service

Submissions Queue

Code Scoring Service summary

9.3 Student Profile Service

Update Student Scores function

9.4 Analytics Service

Kinesis Firehose

AWS Glue and Amazon Athena

QuickSight

Part 4 The future

10 Blackbelt Lambda

10.1 Where to optimize?

10.2 Before we get started

How a Lambda function handles requests

Latency: Cold vs. warm

Load generation on your function and application

Tracking performance and availability

10.3 Optimizing latency

Minimize deployment artifact size

Allocate sufficient resources to your execution environment

Optimize function logic

10.4 Concurrency

Correlation between requests, latency, and concurrency

Managing concurrency

11 Emerging practices

11.1 Using multiple AWS accounts

Isolate security breaches

Eliminate contention for shared service limits

Better cost monitoring

Better autonomy for your teams

Infrastructure-as-code for AWS Organizations

11.2 Using temporary stacks

Common AWS account structure

Use temporary stacks for feature branches

Use temporary stacks for e2e tests

11.3 Avoid sensitive data in plain text in environment variables

Attackers can still get in

Handle sensitive data securely

11.4 Use EventBridge in event-driven architectures

Content-based filtering

Schema discovery

Archive and replay events

More targets

Topology

appendix A Services for your serverless architecture

appendix B Setting up your cloud

appendix C Deployment frameworks

index

front matter

preface

Serverless technologies occupy an exciting space at the moment. Products like AWS Lambda and DynamoDB have been around for a few years, yet they still feel new and thrilling, sometimes mysterious or puzzling. Many folks worldwide discuss, learn, and implement systems with serverless architectures, yet we haven’t yet seen a mass level of adoption like that of containers. Cloud providers such as AWS continue to grow. However, individuals and organizations still ask questions such as, is serverless right for me, and how do I architect a system correctly from the myriad of available components and options?

We’ve written this book to address some of the more interesting questions we’ve seen across the industry and our technical community. We decided to look at use cases for serverless and explore problems that usually wouldn’t seem like a good fit. More importantly, we’ve tried to convey what it is to have a serverless-first mindset. Our recipe is simple: When you have a problem, offload as much of the undifferentiated heavy lifting onto AWS or another provider and apply the principles of serverless architectures. And, if that doesn’t produce a satisfactory answer, only then go and look at other technologies that may help. It’s important to reiterate that you should always use the right tool for the right job. However, having a set of principles and practices, like viewing a potential solution through a serverless prism first, gives you a map and helps make better, more robust decisions.

This book shows a few examples of us doing it in practice. We discuss how to approach several problems using serverless architectures, what criteria to consider, and how to deal with architectural trade-offs. We also present three real-world companies that have built interesting systems using serverless architectures. These companies dealt with the same kinds of problems you might be solving right now, so it’s worth checking out those chapters to see what potential solutions or ideas exist.

If you are entirely new to serverless architectures, do not worry! The first three chapters introduce you to serverless and even get you building a small application. If you are an expert already, you will enjoy the last two chapters that go deeper into AWS Lambda and discuss emerging practices. And, before we let you go, one other thing: the vast majority of this second edition is new. If you read our first edition, we think that you will find this a very different book. We hope you find something interesting and helpful in this book and come with us on this exciting serverless journey.

acknowledgments

The second edition of Serverless Architectures on AWS couldn’t have been written without the encouragement and support from my peers, colleagues, family, and friends. I am lucky to be surrounded by passionate technologists who continuously encourage, give feedback, and provide invaluable advice.

First and foremost, I want to say thank you to my two co-authors: Yan Cui and Ajay Nair. I am fortunate to know these two fantastic world-class experts to whom education and community is always foremost. I cannot describe how thankful I am to Yan and Ajay for helping to write this book and making it uniquely special among the technical literature available today. I am forever grateful to both of you for being there through this journey, teaching me, and sharing the benefit of your experience.

Second, I would like to thank our editor, Toni Arritola, who once again made the writing of this book a great experience. Toni did a lot of work on the first edition of this book, and she worked just as hard on the second edition. It bears repeating again that Toni’s thoughtful feedback on the book’s structure, language, and narrative was extraordinarily helpful. And, after all these years of dealing with my slipping deadlines, her attention to detail and enthusiasm kept the book and its authors going.

It goes without saying that I want to thank Sam Kroonenburg too. Sam originally introduced me to AWS Lambda and the serverless mindset. He co-founded A Cloud Guru, the first truly serverless startup, and gave me the opportunity to hone my skills. If it wasn’t for Sam and my experience at A Cloud Guru, this book wouldn’t exist. I would be amiss if I also didn’t thank Ryan Kroonenburg, the other co-founder of A Cloud Guru and Sam’s brother. Both Sam and Ryan played a big part in the popularization of serverless technologies with A Cloud Guru, and also the founding of the first technology conference focused entirely on serverless called Serverlessconf (ask me for stories over a drink!). Thank you, Sam and Ryan!

I’d also like to thank a few others who for years have given me great feedback and encouragement. A big thank you to Tim Wagner, Drew Firment, Allan Brown, Nick Triantafillou, Tait Brown, Alicia Cheah, Forrest Brazeal, Peter Hanssens, Kim Bonilla, Ilia Mogilevsky, as well as my fellow AWS serverless heroes and all my colleagues and friends at A Cloud Guru/Pluralsight. I’d also like to thank Mike Stephens from Manning for helping to bring this book to fruition.

To all the reviewers: Aliaksandra Sankova, Bonnie Malec, Borko Djurkovic, Camal Çakar, Carl Nygard, Chris Kottmyer, Christopher Fry, Daniel Vásquez, Eugene Serdiouk, Giampiero Granatella, Gregory Reshetniak, Javier Collado Cabeza, Jose San Leandro, Julien Pohie, Kelly E. Hair, Kirstie G. McKenzie, Lucian-Paul Torje, Matteo Gildone, Michael Kumm, Michal Rutka, Miguel Montalvo, Mikołaj Wawrzyniak, Patrick Steger, Paul Mcilwaine, Robert Kulagowski, Sal DiStefano, Sau Fai Fong, Shaun Hickson, Steve Hansen, Valeriy Arsentyev, Vignesh Muthuthurai, and William Dixon, your suggestions and feedback made this a better book.

Finally, I’d like to thank my family, including my dad, my brothers Igor and Dimitri, and their spouses Rita and Alexandra. They’ve had to find more strength to listen to me go on about the book for yet another year. And thank you to Durdana Masud, who helped me greatly throughout my writing, with both the first edition and the second edition.

—Peter Sbarski

I would like to thank Peter Sbarski for the opportunity to contribute to this book, and Toni Arritola for her help and guidance every step of the way. It has truly been a pleasure and honor to work with them over the past 12 months.

I would also like to thank Anahit Pogosova for sharing details of the amazing work that she and her team at Yle have done. The knowledge she shared with me was very valuable and contained so many useful and actional tips for anyone building data pipelines using serverless technologies. I hope I have done her work justice in chapter 6, even though I had to leave out so much. We can easily fill a whole book with the information she shared with me.

I would also like to thank a few friends and colleagues who have given me opportunities and guidance along the way. I wouldn’t be the man I am today without you, and your friendship means everything to me; I can’t wait to catch up with you all in person soon. Big thanks to Darryl Jennings, Tom Newton, Brett Johansen, Domas Lasauskas, Scott Smethurst, Diana Ionita, Simon Coutts, Bruno Tavares, Heitor Lessa, Erez Berkner, Aviad Mor, John Earner, Simone Basso, and Alessandro Simi.

Last, but not least, I would like to thank my wonderful wife, Yinan Xue, for all the support and encouragement she has given me and continues to give me over the years. You are my best friend and the love of my life, and I look forward to growing old and wrinkly with you!

Oh, I almost forgot, I would like to thank my cat, Ada, for bringing so much joy into our lives and all the love she has given us. That scar you left on my thigh five years ago is still visible to this day, I really . . . wait a minute. . . .

—Yan Cui

I always hoped to create a lasting contribution to the developer community and am so excited to see that finally happen with the second edition of Ser verless Architectures on AWS. My biggest thanks to Peter Sbarski for making this happen and for the opportunity to create this work with Yan Cui and him. It has been an honor and a pleasure to be a part of the team with these serverless luminaries. Thank you to the crew at Manning, and our editor Toni Arritola, for their everlasting patience, thoroughness, and guidance.

This book is dedicated to the serverless community. We at AWS and other providers may build the technology, but it is you, the community and the customers, that put it to work to the benefit of the world. I hope this book captures the passion, depth, and breadth that you deserve. Keep raising the bar and changing the world, one event at a time.

Finally, a special shout out to Tim Wagner for getting the whole serverless universe started.

—Ajay Nair

about this book

Serverless technologies and architectures are fascinating and unique. They present a different way of building software in a cloud environment. This is because serverless is about offloading the undifferentiated heavy lifting to others, reducing certain operational concerns, moving toward event-driven computing, and giving yourself space to focus on what’s important—the core goals of your business or project. This book teaches about the serverless approach to the design of systems. You will read how other companies have solved problems using a serverless approach on AWS and dive into numerous discussions about architecture.

Along the way, you will learn more about event-driven computing, useful design patterns, organizing and deploying your code, and security. This book isn’t a collection of tutorials you can find online. Instead, it is an attempt to share our thinking and understanding of the future of cloud computing, which we think is serverless.

This book is in four parts. The first part takes you through basic serverless principles as well as crucial architectures and patterns. You will also build a small serverless application in AWS to get your hands dirty. It’ll be a fun one; your application will convert video files from one format to another without running a server.

The second part focuses on three case studies from Yubl, A Cloud Guru, and Yle. You will read how other companies have solved business and technical challenges with a serverless approach. The third part is about architecture. Here you will learn how to adopt the serverless-first mindset, think about the pros and cons of different architectural implementations, and tackle unexpected challenges. The three examples we present are all different, showing that a serverless approach to the design of systems is versatile and flexible.

The fourth and final part of the book looks at the internals of AWS Lambda and emerging AWS practices. If you are already an expert on AWS and serverless, you may find this section to be particularly fascinating.

The second edition of Serverless Architectures on AWS is for serverless veterans and beginners alike. No matter your experience, we think you will find something valuable in these pages. We hope that this book will inspire you to think serverless first. Now, let’s read and build!

About the code

This book provides many examples of code. These appear throughout the text and as separate code listings. To accommodate long lines of code, listings include line-continuation markers (). Code appears in a fixed-width font just like this, so you’ll know when you see it.

This book is about architecture and, as such, it is not heavy on source code. Chapter 2 is the only practical chapter. The source for chapter is available on GitHub at http://github.com/sbarski/serverless-architectures-aws-2. If you’d like to contribute, open a pull request and we’d be happy to consider your changes. If you see a problem, please file an issue.

liveBook discussion forum

Purchase of Serverless Architectures on AWS, Second Edition includes free access to liveBook, Manning’s online reading platform. Using liveBook’s exclusive discussion features, you can attach comments to the book globally or to specific sections or paragraphs. It’s a snap to make notes for yourself, ask and answer technical questions, and receive help from the authors and other users. To access the forum, go to https://livebook.manning.com/#!/book/serverless-architectures-on-aws-second-edition/discussion. You can also learn more about Manning’s forums and the rules of conduct at https://livebook.manning.com/#!/discussion.

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the authors can take place. It is not a commitment to any specific amount of participation on the part of the authors, whose contribution to the forum remains voluntary (and unpaid). We suggest you try asking the authors some challenging questions lest their interest stray! The forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

about the authors

Peter Sbarski is VP of Education & Research at A Cloud Guru, AWS Serverless Hero, and the organizer of Serverlessconf, the world’s first conference dedicated entirely to serverless architectures and technologies. His work at A Cloud Guru allows him to research and write about serverless architectures, cloud computing and AWS. Peter is always happy to talk about serverless technologies at conferences and meetups year round. His other passions include technical education, and innovation in technology and cloud computing. Peter holds a Ph.D. in Computer Science from Monash University, Australia. He can be found on Twitter (@sbarski) and LinkedIn (linkedin.com/in/petersbarski).

Yan Cui is a developer advocate at Lumigo and an independent consultant who helps clients around the world go faster for less by successfully adopting serverless technologies. He has over a decade of experience running production workloads at scale on AWS and has worked as architect and principal engineer within a variety of industries including banking, e-commerce, sports streaming, and mobile gaming. Yan is an AWS Serverless Hero and a regular speaker at conferences internationally. He is the author of Production-Ready Serverless (Manning, 2018) and co-author of F# Deep Dives (Manning, 2014), and he has also self-published several popular courses such as the AppSync Masterclass. He can be found on Twitter (@theburningmonk) and LinkedIn (linkedin.com/in/theburningmonk) and writes regularly on his blog (theburningmonk.com).

Ajay Nair is a Director of Product and Engineering with Amazon Web Services. He is the founding product leader for AWS Lambda and helped build the AWS serverless portfolio over the last several years. Ajay has spent his career focusing on cloud native platforms, developer productivity, and big data systems. He loves spending his days helping developers do more with less and delighting customers with the power of technology. Ajay holds a Masters in Information Systems Management from Carnegie Mellon, USA, with a Bachelors in Electrical and Electronics Engineering from Kerala University, India. You can find Ajay sharing thoughts on everything from serverless to product management on Twitter (@ajaynairthinks) or on LinkedIn (linkedin.com/in/ajnair).

about the cover illustration

The figure on the cover of Serverless Architectures on AWS, Second Edition is Man from Stupno/Sisak, Croatia, from a book by Nikola Arsenović, published in 2003. The book includes finely colored illustrations of figures from different regions of Croatia, accompanied by descriptions of the costumes and of everyday life.

In those days, it was easy to identify where people lived and what their trade or station in life was just by their dress. Manning celebrates the inventiveness and initiative of today’s computer business with book covers based on the rich diversity of regional culture centuries ago, brought back to life by pictures from collections such as this one.

Part 1 First steps

If you are new to serverless architectures, you’ve come to the right place. The first three chapters of this book will give you an introduction to this exciting technology and even get you to build a small serverless application of your own. The first chapter provides an overview of serverless technologies and a discussion about where we are today. The second chapter is more practical; it focuses on giving you a hands-on experience with AWS and services such as AWS Lambda. The third chapter describes popular and useful serverless patterns. Let’s get started!

1 Going serverless

This chapter covers

Traditional system and application architectures

Key characteristics and benefits of serverless architectures

How serverless architectures and microservices fit into the picture

Considerations when transitioning from server to serverless

What’s new in this second edition?

If you ask software developers what software architecture is you might get answers ranging from it’s a blueprint or a plan to a conceptual model to the big picture. This book is about an emerging architectural approach that has been adopted by developers and companies around the world

Enjoying the preview?
Page 1 of 1