Serverless & Well Architected
Tags: serverless, aws, cleancode, beginners
Published: 2023-03-17 00:48:53

Over the last few days, we've discussed a number of topics in the serverless space, covering [storage](https://dev.to/aws-heroes/serverless-storage-50i3), [APIs](https://dev.to/aws-heroes/serverless-apis-5bdp), [compute](https://dev.to/aws-heroes/serverless-compute-3bgo), and [everything in between](https://dev.to/aws-heroes/serverless-orchestration-3879). We've got all the components to build a fully functional, robust application in place, but before you run off and create The Next Big Thing, we have to cover one more crucial topic: [Well Architected](https://aws.amazon.com/architecture/well-architected/?wa-lens-whitepapers.sort-by=item.additionalFields.sortDate&wa-lens-whitepapers.sort-order=desc&wa-guidance-whitepapers.sort-by=item.additionalFields.sortDate&wa-guidance-whitepapers.sort-order=desc). The Well Architected Framework is a set of guidelines or best practices that AWS introduced a few years ago. The six "pillars" of Well Architected are [Security](https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/welcome.html), [Cost](https://docs.aws.amazon.com/wellarchitected/latest/cost-optimization-pillar/welcome.html), [Operational Excellence](https://docs.aws.amazon.com/wellarchitected/latest/operational-excellence-pillar/welcome.html), [Reliability](https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/welcome.html), [Performance Efficiency](https://docs.aws.amazon.com/wellarchitected/latest/performance-efficiency-pillar/welcome.html), and [Sustainability](https://docs.aws.amazon.com/wellarchitected/latest/sustainability-pillar/sustainability-pillar.html). These concepts are not new, but by defining them in this way, AWS has established a reference that is easy to use and understand when evaluating your applications for best practices. In fact, AWS has created a [Well Architected Tool & Review process](https://aws.amazon.com/well-architected-tool/) centered around the six pillars, asking you questions about your application to review yourself or with your team. Before you start building your application, I would highly recommend you go through a formal Well Architected Review. You don't need to answer every single question, in fact some might not be applicable, but going through this exercise gets you thinking about how you want to architect your application, even highlighting key decision trade-offs, or potential issues that you haven't thought of just yet. In the subsections that follow, we'll talk about each of the pillars in a little more detail, and I'll briefly cover [Well Architected Lenses](https://docs.aws.amazon.com/wellarchitected/latest/userguide/lenses.html).

**Security**

![Lock keeping items secure. Image via Unsplash.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w21as3t5slilesn51nvb.jpg)

Simply put, how are you securing your app? Are you using authorization and authentication with [IAM users, roles, and policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) to limit access to your resources? Setting up [permission boundaries](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html) and using [KMS keys](https://aws.amazon.com/kms/) for encryption? This can look like any number of measures, but the important idea here is, are you thinking about how to secure your app? Some of the questions in this space may not be applicable. This could be an app just for you, or one that isn't storing any data to worry about, or it could be wide open to the public and have no personal information to worry about. You don't need to have every single security measure in place for your application, but you do need to think about these things, and make conscious, defendable decisions about your [application security](https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/welcome.html).

**Cost**

![Jar of money with a plant. Image via Unsplash.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g4nhh711kxnt3s66robn.jpg)

This one is pretty straightforward - I don't know anyone who gets excited when their cost or bills go up in price. Obviously, we all want to optimize for a low-cost application solution, whether this is for personal use, your business, or the company you work for (you may not care about that one personally, but I can tell you THEY certainly care about the bottom line). Look at the [pricing model](https://aws.amazon.com/pricing/?aws-products-pricing.sort-by=item.additionalFields.productNameLowercase&aws-products-pricing.sort-order=asc&awsf.Free%20Tier%20Type=*all&awsf.tech-category=*all) and see if there are any ways to cut costs. Some easy ones could be to minimize the number of API calls you're making, or utilize [Lambda Powertools](https://awslabs.github.io/aws-lambda-powertools-python/2.9.1/) to optimize your lambda function for memory & performance. If you've exhausted every option here, that's okay. Cost is typically a trade-off; you may be ok spending more money to make sure your application is secure, reliable, and not hindered in performance. Again, the idea here is that you're actively aware of where your money is going, and you've [reviewed your optimization options thoroughly](https://docs.aws.amazon.com/wellarchitected/latest/cost-optimization-pillar/welcome.html).

**Operational Excellence**

![Group working at laptop computers. Image via Unsplash.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3m75wo0y0yo2max4eww.jpg)

One of my favorite topics to talk about is '[Clean Code](https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882)', or better known as best practices within your code. Although this could cover many of these pillars, it arguably fits squarely within [Operational Excellence](https://docs.aws.amazon.com/wellarchitected/latest/operational-excellence-pillar/welcome.html). This pillar is all about building robust applications, code that is easy to understand, read, and maintainable, and having effective development processes in place. Creating small, logical code blocks, making small & frequent code changes, [reviewing code](https://about.gitlab.com/topics/version-control/what-is-code-review/#:~:text=Code%20reviews%2C%20also%20known%20as,developers%20learn%20the%20source%20code.) periodically, having ample error handling, logging, and monitoring, and so much more fall into this category. For me, this one is sort of like a "catch all" pillar; not because it isn't well defined, but because it encompasses so many parts of the application development cycle. Many of the pillars overlap, but it is very likely that this one in particular will have overlap with one or more of the other pillars at any given time.

**Reliability**

![Chairs relying on each other. Image via Unsplash.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6u0e706lmolbibz4egz.jpg)

Is your application stable? Do you [backup your data](https://aws.amazon.com/backup/) regularly? Do you have [failovers](https://docs.aws.amazon.com/whitepapers/latest/web-application-hosting-best-practices/failover-with-aws.html) or other fail-safe measures in place? Can your application handle a large influx of traffic, or will any changes to the 'average' case break your current functionality? The key question this pillar asks is - are you prepared? Outages are never fun, especially when they significantly impact your customers, but they can (and they do) happen to the best of us. By reviewing the questions in the reliability pillar, you are thinking about your application's [disaster recovery plans](https://docs.aws.amazon.com/whitepapers/latest/disaster-recovery-workloads-on-aws/disaster-recovery-options-in-the-cloud.html), backing up your data, and having processes in place for the 'worst-case scenario'. Hopefully by completing a [reliability review](https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/welcome.html), these things don't occur as often, or aren't as widespread as they might've been before a review.

**Performance Efficiency**

![Performance on the track. Image via Unsplash.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8s0bfsx4dfn0k6g5nuaa.jpg)

Closely related to the Operational Excellence and Reliability pillars, the [Performance Efficiency](https://docs.aws.amazon.com/wellarchitected/latest/performance-efficiency-pillar/welcome.html) pillar is, you guessed it, all about how well your application is performing. What I enjoy most about this pillar is if you're taking advantage of serverless architectures, you're already well on your way to having this one covered, as it's one of the [five design principles](https://aws.amazon.com/blogs/apn/the-6-pillars-of-the-aws-well-architected-framework/) to adhere to. This is about your application running smoothly, scaling effectively, and taking advantage of only the resources you need. This is another big "trade-off" pillar, since you may compromise your performance in some cases to comply with security or save on cost.

**Sustainability**

![Person holding a plant. Image via Unsplash.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hlr4isgicbiitvpqfwui.jpg)

[Sustainability](https://docs.aws.amazon.com/wellarchitected/latest/sustainability-pillar/sustainability-pillar.html) is a recent addition to the Well Architected pillars, and I think it's a good one. It was [introduced at the end of 2021](https://aws.amazon.com/blogs/aws/sustainability-pillar-well-architected-framework/), and even though it's a focus I love to see, it also means there has not been a ton of guidance shared to optimize for sustainability. If you're invested in areas involving hardware, AI/ML, large sets of data, IoT, etc., this is a bit more obvious to contend to - simply put, you want to use less resources, and more sustainable (or at least recyclable) hardware. WIth serverless, you are already scaling automatically, only paying for what you use, and optimizing for your [event driven architecture](https://aws.amazon.com/event-driven-architecture/), which makes it more difficult to find areas to cut down on usage. My best advice is to review your architecture early & often, and continually try to find ways to [lower your carbon footprint](https://www.nature.org/en-us/get-involved/how-to-help/carbon-footprint-calculator/#:~:text=A%20carbon%20footprint%20is%20the,is%20closer%20to%204%20tons.) with optimal architectural design, and if you haven't made the jump to serverless yet, maybe that's the first step!

**Serverless Lens**

![A pair of eyeglasses with lenses. Image via Unsplash.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z5t8b3oue9295xu14dki.jpg)

In addition to the six pillars, AWS Well Architected has this concept of [Well Architected Lenses](https://docs.aws.amazon.com/wellarchitected/latest/userguide/lenses.html). Much like a pair of reading glasses, you can apply a specific Lens to your application to 'see' your application in a bit more detail. There are Lenses for [Machine Learning](https://docs.aws.amazon.com/wellarchitected/latest/machine-learning-lens/machine-learning-lens.html), [Data Analytics](https://docs.aws.amazon.com/wellarchitected/latest/analytics-lens/analytics-lens.html?did=wp_card&trk=wp_card), [Financial Services](https://docs.aws.amazon.com/wellarchitected/latest/financial-services-industry-lens/welcome.html?did=wp_card&trk=wp_card), and, of course, [Serverless Applications](https://docs.aws.amazon.com/wellarchitected/latest/serverless-applications-lens/welcome.html?did=wp_card&trk=wp_card). These Lenses are simply a set of extra guidelines and questions for each of these six pillars relating specifically to the type of application you are building. They are 'optional', as is the entire Well Architected Review process, but again, if you are building a serverless application, I would highly recommend you complete a Well Architected Review with the Serverless Lens, as it will only strengthen your application posture in the context of these six pillars.

If you'd like to learn more about Well Architected or hear about it in practice, I have actually given a [recent talk on the subject with Build On at AWS Re:Invent](https://www.twitch.tv/videos/1674539542?collection=T1passDrLhdY6Q). This is an area of technology I have been very passionate about, and I truly believe these pillars and Well Architected Reviews are well worth the time and effort. We're coming up to end of our team together this week (I know, already?!) so for our last day tomorrow, I'm excited to summarize what we've learned so far, and present you with some next steps for going beyond the serverless basics.*

*This is part of a series that will be covered here, but I also encourage you to follow along with the rest of the series on [90DaysOfDevOps](https://github.com/MichaelCade/90DaysOfDevOps).