DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

jainnehaa
jainnehaa

Posted on

FaaS : Function as a Service

Function as a service (FaaS) is a cloud computing services providing a platform to customers to develop, run, and manage application functionalities, without the complexity of building and maintaining the infrastructure associated with developing and launching an app.

Building an application following this model is one way of achieving a serverless architecture and is typically used when building microservices applications. Use cases for FaaS are associated with "on-demand" functionality that enables the supporting infrastructure to be powered down and not incur charges when not in use.

AWS Lambda was the first FaaS offering by a large public cloud vendor, followed by Google Cloud Functions, Microsoft Azure Functions, IBM/Apache's OpenWhisk (open source) in 2016 and Oracle Cloud Fn (open source) in 2017.

Let's understand how a function work with a serverless framework, taking Azure Functions into consideration :

Serverless Functions execute codeβ€”written in the language of one's choice with Azure Functions, with an event-driven compute experience.
Azure Functions scales on demand and one pays only for the time your code is executed.
Available as a managed service in Azure and Azure Stack, the open source Functions runtime also works on multiple destinations, including Kubernetes, Azure IoT Edge, on-premises, and even in other clouds.

A Function should be written to perform a single job such as:
Saving a user to the database
Processing a file in a database
Performing a scheduled task
Separation of concerns should be taken into consideration

Few sample scenarios to implement Azure Functions :

Sample scenarios set to implement Azure Functions

Anything that triggers an Azure Function to execute is regarded as an Event or Trigger. A trigger defines how a function is invoked and a function must have exactly one trigger. Triggers have associated data, which is often provided as the payload of the function.
Few Triggers on Azure Functions are :

  • An HTTP Trigger (e.g., for a REST API)
  • A scheduled timer (e.g., run every 5 minutes)
  • A Service Bus Queue trigger (e.g. a workitem from another Function)
  • An IoT/Event Hub message (e.g., a message from a device or service)
  • A Webhook fires (e.g., Github project update) And many more..

Binding to a function is a way of declaratively connecting another resource to the function; bindings may be connected as input bindings, output bindings, or both. Data from bindings is provided to the function as parameters.
You can mix and match different bindings to suit your needs. Bindings are optional and a function might have one or multiple input and/or output bindings.
Like, Blob Storage, Queue, CosmosDB etc

Triggers and bindings let you avoid hardcoding access to other services.
Each function has its own code file and binding configuration file as function.json where triggers are triggers are configured.
(used along different languages like Java, Javascript, Python, C#).

{
"scriptFile": "azure-functions-example.jar",
"entryPoint": "com.example.Function.echo",
"bindings": [
{
"type": "httpTrigger",
"name": "req",
"direction": "in",
"authLevel": "anonymous",
"methods": [ "GET","POST" ]
},
{
"type": "http",
"name": "$return",
"direction": "out"
}
]
}

AWS Lambda has similar use case and can cater to file processing, stream processing, web applications, IoT backends and mobile backends.
One such scenario is illustrated as below - File Processing :

AWS Lambda File Processing

Amazon Simple Storage Service (Amazon S3) to trigger AWS Lambda data processing in real time after an upload, or connect to an existing Amazon EFS file system to enable massively parallel shared access for large-scale file processing.

References :
docs.microsoft.com/azure-functions
aws.amazon.com/lambda/
serverless.com
azure.microsoft.com/serverless/

Wikipedia - Serverless Computing
Wikipedia - FaaS
Wikipedia - Microsoft Azure

Image Resources :
AWS Lambda - File Processing

Top comments (0)

πŸ€” Did you know?

Β 
✍️ Writing your own article is easy (we even support markdown).