Solutions Architect Tips - Decoding the AWS Serverless Design Principles
Tags: serverless, aws, career
Published: 2021-03-30 13:34:13

---
title: Solutions Architect Tips - Decoding the AWS Serverless Design Principles
published: true
description: AWS offers standard principles on how to design serverless systems. Discover how they translate into guidelines for architecting new projects.
tags: 
  - serverless
  - aws
  - career
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gb1a57u1jlrzkw85xweh.jpg
canonical_url: https://www.readysetcloud.io/blog/allen.helton/decoding-the-aws-serverless-design-principles/
---

If you've worked with AWS in any sort of capacity, you've probably learned they have a unique way of doing things. They start off meetings [reading documents in silence](https://www.inc.com/justin-bariso/jeff-bezos-knows-how-to-run-a-meeting-here-are-his-three-simple-rules.html), they begin new projects [by working backward](https://www.readysetcloud.io/blog/allen.helton/working-backwards-my-experience-with-the-aws-design-strategy-f4bd90c87b8), and no matter what they do they drive their [leadership principles](https://www.amazon.jobs/en/principles)....hard.

There's a reason Amazon basically runs the world. Their way of doing things work. 

Among the many artifacts they produce to help companies build best-in-class software is their general design principles. If you've ever been through an [AWS Well-Architected](https://aws.amazon.com/architecture/well-architected) review, you know all about them in excruciating detail (in a good way). 

If you're into [building serverless applications](https://www.readysetcloud.io/blog/allen.helton/how-and-why-you-need-to-start-generating-your-diagrams), AWS has an entirely different set of design principles you should follow. They take the core pillars of the Well-Architected model and look at them through a [serverless application lens](https://docs.aws.amazon.com/wellarchitected/latest/serverless-applications-lens/welcome.html).

Today we're going to take a look at [all 7 principles](https://docs.aws.amazon.com/wellarchitected/latest/serverless-applications-lens/general-design-principles.html) and talk about how those translate to your designs as a solutions architect.

## 1. Speedy, Simple, Singular
*Functions are concise, short, single purpose and their environment may live up to their request lifecycle. Transactions are efficiently cost aware and thus faster executions are preferred.*

**What this means -** Functions, in this case Lambdas, are supposed to be focused. They spin up, do a job, and spin down.

Do what you can to minimize execution time. Take advantage of asynchronous workflows where you can. Drop a task in an SQS queue for additional processing and stop execution of the originating Lambda. Try to avoid calling another Lambda from within a Lambda. 

Functions should follow the [single responsibility principle](https://deviq.com/principles/single-responsibility-principle). If you need to do two separate actions, consider using two separate functions.

## 2. Think concurrent requests, not total requests
*Serverless applications take advantage of the concurrency model, and tradeoffs at the design level are evaluated based on concurrency.*

**What this means -** Don't spend hours and hours trying to figure out how to optimize your processes into as few requests as possible. That's not the point. 

This principle is important because it tells solutions architects to rely on the ability of a serverless application to [horizontally scale during peak times](https://docs.aws.amazon.com/lambda/latest/dg/invocation-scaling.html). If you follow design principle number one, your functions will be short and sweet. They will respond in a couple hundred milliseconds.

During peak times, your application will scale out. It might be serving 100,000 requests a minute, but to your end users it will feel like they are the only one using the system. It will be fast. The software will respond to a heavy load. 

With this is mind, don't worry too much about the number of requests you're making. Design your systems to take advantage of AWS's ability to automatically scale. 

If you can break down a long running task into multiple pieces, do it. This design principle is about [scaling horizontally over scaling vertically](https://www.section.io/blog/scaling-horizontally-vs-vertically/). By taking a big, heavy task and turning it into small, singular tasks, you result in more performant software that also costs you less money.

![Photo by [Annie Spratt](https://unsplash.com/@anniespratt?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/not-sharing?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)](https://readysetcloud.s3.amazonaws.com/serverlessdesign_1.jpg)
*Photo by [Annie Spratt](https://unsplash.com/@anniespratt?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/not-sharing?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)*

## 3. Share Nothing
*Function runtime environment and underlying infrastructure are short-lived, therefore local resources such as temporary storage is not guaranteed. State can be manipulated within a state machine execution lifecycle, and persistent storage is preferred for highly durable requirements.*

**What this means -** Assume the function is stateless. Go to the database every time you need to do something with entity state. Don't rely on globally-scoped variables.

A trick to optimize Lambda performance is to [instantiate sdk clients globally](https://pages.awscloud.com/rs/112-TZM-766/images/2020_0316-SRV_Slide-Deck.pdf#page=19) (check out slide 19), but leave it at that. Since your lambdas spin up and down all day, you never know what will or won't be there.

Start every execution like it's brand new, and load what you need every time. 

## 4. Assume no hardware affinity
*Underlying infrastructure may change. Leverage code or dependencies that are hardware-agnostic as CPU flags, for example, may not be available consistently.*

**What this means -** You chose serverless for a reason: to not have to deal with hardware. Serverless functions are meant to be run at a higher level than CPU flags or other hardware commands. 

When designing a system, forget about server-side hardware. Use environment variables to do configurations and [power-tune your functions](https://www.readysetcloud.io/blog/allen.helton/power-tuning-your-serverless-api-for-happy-customers) after you've implemented it.

## 5. Orchestrate your application with state machines, not functions
*Chaining Lambda executions within the code to orchestrate the workflow of your application results in a monolithic and tightly coupled application. Instead, use a state machine to orchestrate transactions and communication flows.*

**What this means -** If you're following principles 1 and 2, you should have designed a robust, modular system. A command might result in 4 or 5 Lambdas to complete. Remember, this is a good thing. You've enabled the system to scale horizontally and allowed higher throughput and performance in the process.

Don't invoke Lambdas from within other Lambdas. It's slower, [considered an anti-pattern by AWS](https://aws.amazon.com/blogs/compute/operating-lambda-anti-patterns-in-event-driven-architectures-part-3/), and significantly more expensive. It is more expensive because you have to pay for execution time of the inner Lambda *and* the calling Lambda while it waits.

[Step Functions](https://aws.amazon.com/step-functions/) are designed to resolve those issues. They give you an easy to digest state machine diagram of your workflow, and second-to-none traceability through executions.

If a Step Function seems a bit heavy for your system, you could try an [express workflow](https://aws.amazon.com/about-aws/whats-new/2019/12/introducing-aws-step-functions-express-workflows/), which is much lighter, has higher throughput/concurrency, and charged similarly to Lambda.

![Image by [Joseph Mucira](https://pixabay.com/users/jmexclusives-10518280/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5614048) from [Pixabay](https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5614048)](https://readysetcloud.s3.amazonaws.com/serverlessdesign_2.jpg)
*Image by [Joseph Mucira](https://pixabay.com/users/jmexclusives-10518280/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5614048) from [Pixabay](https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5614048)*

## 6. Use events to trigger transactions
*Events such as writing a new Amazon S3 object or an update to a database allow for transaction execution in response to business functionalities. This asynchronous event behavior is often consumer agnostic and drives just-in-time processing to ensure lean service design.*

**What this means -** Asynchronous operations are your friends. Your customers don't need to wait on everything that happens in the system. Embrace [event-driven architectures](https://www.readysetcloud.io/blog/allen.helton/adding-webhooks-to-your-app-with-amazon-sns).

This is how software engineers naturally think. *If this happens, then this other thing should occur.* 

Serverless applications by nature are distributed systems. To get the pieces playing together, use basic events like *when a new document finishes uploading* or a *[DynamoDB stream](https://aws.amazon.com/blogs/database/dynamodb-streams-use-cases-and-design-patterns) that is triggered after a database write* to perform follow-on activities. 

> Software doesn't have to be synchronous anymore

Design your system with the intention to keep your users waiting as little as possible. 

## 7. Design for failures and duplicates
*Operations triggered from requests/events must be idempotent as failures can occur and a given request/event can be delivered more than once. Include appropriate retries for downstream calls.*

**What this means -** Anomalies happen. There will be times where a Lambda that was triggered off an event randomly fails. As a solutions architect, you must design the system in a way that can handle identical requests and have the same outcome performed on the system. 

This is [idempotency](https://www.restapitutorial.com/lessons/idempotency.html). 

You should design idempotency and retries into (almost) every Lambda in your app. Step Functions provide an easy way to [retry Lambdas with a configurable backoff rate](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html#error-handling-retrying-after-an-error) in the event you have an issue.

{% twitter 632260618599403520 %}

Since you can't reliably trust if requests are going to come in the right order or that they will come in only once, designing systems with that in mind is critical. 

## Conclusion
AWS really knows their stuff. It is smart to keep these in your back pocket when designing a serverless solution. 

We all want systems to be fast, reliable, and cost-effective. Following the AWS serverless design principles will make sure we do that. 

So remember, keep if focused. Keep it small. Design for concurrent executions. Don't worry about the number of calls you're making (to a point). Orchestrate with managed services. Design with replay-ability in mind.

Serverless can be scary and a bit intimidating at times, but it takes practice. A good solutions architect makes a complex solution out of a complex problem. A great solutions architect makes a simple solution out of a complex problem. 

Be great. Use the tools the way they were meant to be used. 

Cheers.