Benefits of Serverless and Event Driven Design

Image for post
Image for post

What are the benefits

The two main features of serverless are computing are cost and elasticity.

Cost benefits of serverless

You dont need to worry about idle costs, as most cloud providers will provide a so called function as a service where you pay for the amount of execution time, over the amount of resources consumed.

  • AWS Fargate — where again you only pay for the execution time, but has more freedom since it runs a container image, meaning pretty much anything that can be containerised can be run. Fargate doesn’t have a max executing time, so effectively you can run serverless 24/7.
Image for post
Image for post

Elasticity benefits of serverless

Using serverless offerings, you can essentially support scaling from zero. This means if your workload is not needed, you do not need to pay for idle servers. The challenge with this would be in the scheduling and optimising of these cloud resources.

Where does event driven design come into play?

Serverless and Stateless go hand in hand. Services such as AWS Lambda can expect to run asynchronously, and not feed back to something waiting for an operation to complete.

Some serverless design patterns:

A simple serverless web request with some processing and storing a result.

A good example of this would be a contact us form on a webpage.

Image for post
Image for post
  1. Api Gateway passes this data onto an SQS queue.
    At this point, it returns to Api Gateway, and the user is returned a 200 status code.
  2. The SQS triggers a lambda to process the message. This could be anything from cleaning the data, sending an email etc.
  3. The lambda also stores the data in a serverless database, this is just a form of persistence, and could be used for detecting duplicates etc.
Image for post
Image for post

An action performed on a file on the back of an upload

A good example would be image processing on an uploaded file.

Image for post
Image for post
  1. Once the file upload is complete, an S3 trigger as invoked, which calls a Lambda
  2. The Lambda performs some kind of processing operation on the file which was uploaded
  3. The result is then stored back in S3

Written by

Technologist who enjoys writing and working with software and infra. I write up all the things I learn as I go along to share the knowledge!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store