Why Go Serverless? Understanding Zappa's Benefits

Let's explore what Serverless is and isn't

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

  • |

Lesson Transcript

  • [00:00 - 00:27] Why serverless? It's important to understand what it means to run in a server less environment. Let's compare the old school or traditional way of using a server versus the new school or serverless environment. Just an important note I want to point out. A server less environment actually uses servers, but those servers are managed and maintained by Amazon on your behalf, so there's no overhead or extra steps you need to do.

  • [00:28 - 00:45] Here's a typical web server stack for a Django application, showing the top of the stack and moving down toward the bottom. At the top of the stack is your Django project, your code that you write. Underneath that is Django and the Python packages. You download and assemble these to get your project working.

  • [00:46 - 00:57] Underneath that, whether you know it, is a web services, gateway interface, or WISGIE. This layer takes the web requests and transforms them into a form that Django can consume easily.

  • [00:58 - 01:17] Underneath that is Apache or EngineX, some sort of web server software that you have to install, configure, and patch. And then there's the underlying operating system. Linux in this case, it could be Windows, but you also have to install, configure, and patch as well as get licenses for that, if applicable.

  • [01:18 - 01:27] Underneath that is some sort of hardware, the physical server that the operating system runs upon. You have to maintain that or your hosting provider has to maintain that.

  • [01:28 - 01:40] And then finally, you have to feed the hardware with power, HVAC or heat ventilation, air conditioning, and physical security, so no one tampers with your physical servers. You or your hosting vendor have to deal with that.

  • [01:41 - 01:49] Now let's compare that stack with a serverless stack. Once again, here's your stack layers. At the top is your Django project that is unchanged.

  • [01:50 - 02:01] Django and Python packages also unchanged. You have to assemble those to create and configure your project. Next, we have a utility called Zappa, which we'll talk about in just a second.

  • [02:02 - 02:13] It's an open source tool that packages web requests to your Django project. Supporting Zappa is AWS Lambda, which is your execution environment.

  • [02:14 - 02:29] Associated with that is your AWS API gateway that actually receives and dist ributes HTTP requests. And finally, Amazon supports multiple regional data centers where they provide power, HVAC, and security.

  • [02:30 - 02:38] It's important to note that everything below Zappa is handled by Zappa. You can think of Zappa as your personal infrastructure team.

  • [02:39 - 02:48] It allows you to focus on the application software, not the supporting layers. AWS provides the robust web hosting without a lot of overhead maintenance.

  • [02:49 - 03:00] So what is Zappa and how does it work? The Zappa utility is an open source tool that enables a Django or Flask application to operate in the AWS Lambda serverless environment.

  • [03:01 - 03:13] This probably sounds like a lot of buzzwords, so let's break it down into more understandable parts. In short, Zappa creates and configures a compatible AWS environment for your Django or Flask project.

  • [03:14 - 03:27] This means your Django project runs in the cloud without having to worry about setting, configuring, or maintaining your own web server. The AWS Lambda environment handles all that while you focus on writing your application code.

  • [03:28 - 03:49] Unlike some other minimal serverless deployment tools, Zappa comes with built-in support for whiskey requests routing to Django or Flask. But you can also run periodic jobs such as database maintenance, calculation jobs, or send messages similar to celery without the overhead.

  • [03:50 - 04:18] Easily map a custom domain name to your project, or respond to many AWS events such as S3 uploads, DynamoDB entries, Kinesis streams, SNS messages, and SQS messages, and more. A key benefit of Zappa is that once you have it in your project, there are no external dependencies to use Zappa. That means you don't have to create a Zappa account or anything like that.

  • [04:19 - 04:37] It's free to download and use for everyone. Naturally, your project will have packaged dependencies that you specify in your requirements file, and Amazon Web Services needs to be running, but aside from that, your environment should be self-contained. You may ask yourself, "Can I use serverless for everything?"

  • [04:38 - 05:13] The answer is a resounding no. It's important to realize that not all applications should be serverless. Serverless applications are generally best for event-driven models like web servers, chatbots, or smart speaker apps. Since you're only paying for CPU cycles that your app uses, apps that are idle for long periods are ideal for serverless migration. If your applications perform heavy calculations or are CPU intensive, such as rendering, modeling, or Bitcoin mining, then look for non-serverless solutions.

  • [05:14 - 05:33] You'll probably find that AWS Lambda will not be cost effective for these applications. But if you're a solo developer or a small team of developers, and you want to focus on getting your website up and running in a robust environment without a lot of overhead, then Zappa is for you.

Why serverless? It's important to understand what it means to run in a server less environment. Let's compare the old school or traditional way of using a server versus the new school or serverless environment. Just an important note I want to point out. A server less environment actually uses servers, but those servers are managed and maintained by Amazon on your behalf, so there's no overhead or extra steps you need to do. Here's a typical web server stack for a Django application, showing the top of the stack and moving down toward the bottom. At the top of the stack is your Django project, your code that you write. Underneath that is Django and the Python packages. You download and assemble these to get your project working. Underneath that, whether you know it, is a web services, gateway interface, or WISGIE. This layer takes the web requests and transforms them into a form that Django can consume easily. Underneath that is Apache or EngineX, some sort of web server software that you have to install, configure, and patch. And then there's the underlying operating system. Linux in this case, it could be Windows, but you also have to install, configure, and patch as well as get licenses for that, if applicable. Underneath that is some sort of hardware, the physical server that the operating system runs upon. You have to maintain that or your hosting provider has to maintain that. And then finally, you have to feed the hardware with power, HVAC or heat ventilation, air conditioning, and physical security, so no one tampers with your physical servers. You or your hosting vendor have to deal with that. Now let's compare that stack with a serverless stack. Once again, here's your stack layers. At the top is your Django project that is unchanged. Django and Python packages also unchanged. You have to assemble those to create and configure your project. Next, we have a utility called Zappa, which we'll talk about in just a second. It's an open source tool that packages web requests to your Django project. Supporting Zappa is AWS Lambda, which is your execution environment. Associated with that is your AWS API gateway that actually receives and dist ributes HTTP requests. And finally, Amazon supports multiple regional data centers where they provide power, HVAC, and security. It's important to note that everything below Zappa is handled by Zappa. You can think of Zappa as your personal infrastructure team. It allows you to focus on the application software, not the supporting layers. AWS provides the robust web hosting without a lot of overhead maintenance. So what is Zappa and how does it work? The Zappa utility is an open source tool that enables a Django or Flask application to operate in the AWS Lambda serverless environment. This probably sounds like a lot of buzzwords, so let's break it down into more understandable parts. In short, Zappa creates and configures a compatible AWS environment for your Django or Flask project. This means your Django project runs in the cloud without having to worry about setting, configuring, or maintaining your own web server. The AWS Lambda environment handles all that while you focus on writing your application code. Unlike some other minimal serverless deployment tools, Zappa comes with built-in support for whiskey requests routing to Django or Flask. But you can also run periodic jobs such as database maintenance, calculation jobs, or send messages similar to celery without the overhead. Easily map a custom domain name to your project, or respond to many AWS events such as S3 uploads, DynamoDB entries, Kinesis streams, SNS messages, and SQS messages, and more. A key benefit of Zappa is that once you have it in your project, there are no external dependencies to use Zappa. That means you don't have to create a Zappa account or anything like that. It's free to download and use for everyone. Naturally, your project will have packaged dependencies that you specify in your requirements file, and Amazon Web Services needs to be running, but aside from that, your environment should be self-contained. You may ask yourself, "Can I use serverless for everything?" The answer is a resounding no. It's important to realize that not all applications should be serverless. Serverless applications are generally best for event-driven models like web servers, chatbots, or smart speaker apps. Since you're only paying for CPU cycles that your app uses, apps that are idle for long periods are ideal for serverless migration. If your applications perform heavy calculations or are CPU intensive, such as rendering, modeling, or Bitcoin mining, then look for non-serverless solutions. You'll probably find that AWS Lambda will not be cost effective for these applications. But if you're a solo developer or a small team of developers, and you want to focus on getting your website up and running in a robust environment without a lot of overhead, then Zappa is for you.