Serverless Functions — No server, just code?

Written by Lucas Rodrigues

 
serveless functions
 
 

Serverless is a new term for function applications. The idea is to send code, where you don't need to handle infrastructure, servers, network, storage. Just code.

But, looking behind the scenes, there will always be a server serving the application but you don't need to care about it, just configure the parameters and send your code to your cloud environment, like AWS created this way to work by using the famous Lambda Functions and Azure created Azure Functions.

 

What is Cloud Functions?

Cloud function or FaaS (Function as a service) is a new way to create applications, where basically you only pay for request and process time. Instead of paying for a traditional Virtual Machine everyday for the whole week, using cloud functions you pay by trigger it and/or duration that the function runs.

The main cloud players (AWS, Azure and Google Cloud) provide several binding automation to trigger your function by, for example if some interaction happens on your databases, sending a payload to Message Service or some file being uploaded to file repository (S3, Blob Storage), your cloud function will warm up an instance to run the code.

 

Programming languages

In Azure is quite limited in terms of programming language, you can only use C#, F#, Java, Javascript, Typescript, PowerShell, Python.

In AWS you have more flexibility to choose your programming language, natively you can use: C#, NodeJS, Go, Java, Ruby PowerShell, Python. But you can use Custom Runtime for lambda functions and you can use any programming language you prefer (https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html)

 

Billing

All cloud providers charge this kind of service by process timing and resource used.

When you want to create a serverless instance in the cloud provider, you need to define the host resource, like CPU Cores and Memory limit, Azure for example, you can select some plans where you can setup the host in different prices.

Azure

If you have a project where it doesn’t need to handle too much resources, a basic plan on Azure cost €0.000014 per execution (https://azure.microsoft.com/en-us/pricing/details/functions)

 

AWS

Running lambda function on AWS using 128MB each millisecond running the application costs $0.0000000021 euros (https://aws.amazon.com/lambda/pricing)

 

If you are using Azure, a basic plan has a limit time to run your application, round about 3 minutes, but AWS there is no limit, if you left a while(true) or a recursive function, you can easily have a big debit in your budget. Really pay attention before deploying cloud functions.

 

How to deploy?

Microsoft Azure, requires to respect a folder structure and some configuration files to run the application on cloud. In case you are using NodeJS or Python, to deploy a function, your cloud provider provides a cli tool (command line interface) where it will zip you application and upload to S3 or Blob Storage, where it will versioned and all zip packages uploaded. In case you want to automate the deploy you can use GitHub Actions to help automate this process in your CI (Continuous Integration) pipeline

 

Scalability

Scalability is one of the biggest advantage to use serverless infrastructure, it is defined by your budget, and the scale is configurable by parameter or configuration file. You define limits of instances or you leave your cloud provider scale for you without limit. Imagine that you have an ecommerce platform and it’s Black Friday, the access will increase a lot, your functions will scale up depending how many users are accessing your platform, when no one is using all functions scale to 0 (zero) instances and no one needs to monitor your server consumption, because everything is managed by the provider.

 

Vendor Lock-In

Imagine that you are using AWS Lambda functions and the billing is quite high and doing a quotation in Azure you realize that it is cheaper compared to AWS, you decide to move your cloud functions to Azure, but you can’t because your lambda functions only works on AWS. If you need to run your functions and migrate to another provider, you’ll need to refactors all projects deployed. There are some alternatives to avoid it, Kubernetes provides a service open source called Knative, where you can run applications in your infrastructure, but the down side is that you don’t have so much integrations.

 

Serverless Database (database as a service)

This topic can be another post, but just doing a quick overview, some database vendors created DaaS (Database as a Service) follow some providers where whole environments are managed by the vendors:

·       Amazon Aurora Serverless: https://aws.amazon.com/rds/aurora/serverless

·       AWS DynamoDB: https://aws.amazon.com/dynamodb

·       FaunaDB: https://fauna.com

·       Azure CosmosDB: https://azure.microsoft.com/en-us/services/cosmos-db

  

Here is a list where you can find all available in Azure:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings?tabs=csharp

 

Pros and Cons:

Pros:

  • Easy to test

  • Some scenarios are cheaper than hosted Virtual Machines.

  • Easy to debug

  • Integrated in the whole cloud

  • Scalability

  • Pay as you use

  • Vendor manage the environment

Cons:

  • Easy to create chaos in your environment.

  • You need to create documentation describing all implemented functions.

  • Not easy to debug the whole flow, because each function is a different instance.

  • Not recommended to use Cloud Functions when you have a heavy compute process.

  • Warm up delay

 

Conclusion

By using Cloud Function you can build projects really quickly, you don’t really care about infrastructure in your application, you are free to integrate easily with others services, but on the other hand you are not free to move to another cloud provider when you want. Before deciding to use this kind of technology you need to find a balance between, costs, team and the kind of problem you are trying to solve.

 

References

·      Knative - https://knative.dev/

·      AWS Lambda - https://aws.amazon.com/lambda/

·      Azure Functions - https://azure.microsoft.com/en-us/services/functions/

·      Google Cloud - https://cloud.google.com/functions/

 

 
Guest User