What is a Serverless Function?

serverless function social.png

Defining Serverless Functions

Serverless functions are single-purpose, programmatic functions that are hosted on managed infrastructure by cloud computing companies. These functions are invoked through the Internet and are designed to automate workflows, reduce latency, and provide on-demand computing capabilities. These serverless architectures are maintained by engineering teams to ensure near-perfect uptime, redundant instances around the globe, and scalability to any incoming network request volume.

Who creates serverless functions?

Serverless functions are created by software developers who are transitioning their product code to serverless platforms to leverage the benefits of serverless computing. It's not the cloud computing companies themselves creating these functions; it’s their customers.

What is the advantage of serverless functions and services?

Serverless functions and services offer numerous advantages including better code maintenance, cost-effective hosting, and the peace of mind resulting from running them on managed infrastructure. This paradigm is quickly becoming popular due to these benefits, and the deployment of new code is quicker, simpler, and easily automated.

What is an example of a serverless function?

All major cloud providers offer serverless functions:

Serverless Infrastructure: Monolithic Architecture vs. Microservice Architecture

Serverless functions can be considered microservices, a popular concept in the serverless environment. There is growing excitement in the software development community about the shift from monolithic platforms to encapsulated microservices.

Why companies are using serverless functions and architectures

Historically, monoliths have large, unified codebases, which require a full deploy of the entire platform for any shipment of new code. This includes new features, but also single line bug fixes.

Monoliths can be practical in some situations, but when a platform’s codebase grows to the stage where the development team is large, some tasks become cumbersome.

An architecture of microservices improves the maintainability of code bases and elevates the overall developer experience for software development teams. Microservices enable a large engineering organization to segment itself into loosely-coupled, autonomous teams. Each team can focus their attention on a few microservices that work independently from the rest of the platform. Note that while microservices can be maintained somewhat independently, they are still players on a unified team.

With microservice architecture, new developers can be on-boarded to engineering projects rapidly, because they do not need to have a deep understanding of an entire monolith to begin making substantial contributions. Another advantage of microservices is that deployment of small code updates to single services results in little or no downtime for customers. When a monolith needs code updates, it might mean that all customers experience downtime for the duration of a serverless deploy function.

Serverless Functions and Functions-as-a-Service (FaaS)

The magic parts of serverless functions are autoscaling and redundant code deployments. This means that an app developer can concern themselves with one thing: writing great application code. The cloud hosting providers call this product offering Functions-as-a-Service, or FaaS for short.

With conventional app hosting, software developers need to repeatedly ask themselves these questions when they write their code:

These questions do not apply when a software system is built upon a platform with Serverless Functions.

Serverless Function code should have entirely stateless logic, so redundant instances will not cause inconsistencies for customers. Cloud hosting providers usually have many points-of-presence around the globe. This means that the servers in which an application runs are nearest to all possible end users. The cloud hosting provider will redundantly deploy a Serverless Function to data centers around the world, at the same time. This is good for a developer's customers because their client-side requests will be responded to with as little latency as possible. All of the networking logic is implemented by the cloud provider.

Google and AWS Serverless Functions with Cloud hosting platforms

Cloud hosting providers that offer Serverless Functions use industry standard best practices for automated code deployment. This means that there is no chance of human error breaking a service during deployment and it allows for fast shipment of new code, with little to no downtime for a web product.

One of the most valuable features of Serverless Function hosting is out of the box autoscaling. Cloud hosting providers have made idle server costs a thing of the past for their customers. Thanks to software products like Kubernetes, services can programmatically scale their infrastructure in an automated fashion. This new kind of “elastic” infrastructure makes hosting more efficient, resulting in big cost savings for companies that buy cloud hosting.

FaaS Providers and Serverless Function Examples

Cloud hosting companies are offering bleeding-edge FaaS platforms. Server costs are going down for consumers globally, as big tech companies build more and more server farms. However, not all FaaS services are created equal. FaaS platforms are not like the telephone company. Each platform has unique scenarios in which it shines.

AWS Lambda Serverless Functions

AWS Lambda is a serverless function environment on Amazon Web Services. The supported programming languages are Java, Go, PowerShell, Node.js, C#, Python, Ruby, Rust, and PHP. It's ideal for on-demand compute operations like file processing.

Azure Functions Serverless Functions

Azure Functions is a serverless function environment on Microsoft Azure. The supported programming languages are C#, F#, Java, Python, JavaScript, and TypeScript. It's ideal for creating single-purpose APIs to add functionality to a platform, such as providing an endpoint for securely storing application data.

Google Cloud Serverless Functions

Google Cloud Functions is a serverless function environment on Google Cloud Platform. The supported programming languages are JavaScript, Python, Go, .NET (C#), Ruby, and PHP. Google Cloud Functions provide serverless compute that interacts succinctly with other Google Cloud Services and client applications. It's ideal for scenarios where data processing is key – like retrieving relevant data from images and videos.

Functions

Functions is a serverless environment to execute functions on the edge, transforming, enriching, and filtering messages as they route through the PubNub network using JavaScript. This serverless platform differs fundamentally from the others since the Function’s event handler executes in response to an event from PubNub, such as when a message is published with PubNub’s Pub/Sub API.

A developer can execute code on an in-transit PubNub message after its publish, but before the message reaches a subscriber. There are other execution configurations including non-blocking after publish, and a REST API Endpoint that can be accessed like a Node.js server. State can be managed using a built using KV-Store within the functions environment. There is also a catalog of open source, 3rd party integrations on the PubNub Functions Catalog.

Which Serverless Provider should I use for my Service?

The answer to this question depends on the type of service that needs to be built. As you can see from the providers described above, there are different programming languages that are usable, depending on the cloud. The most important thing to consider when selecting a provider is: which attributes are mission-critical for my service?

The largest cloud companies (AWS, Azure, Google) offer scalable and cost-effective serverless computing solutions designed to meet a wide variety of use cases with their generic cloud products. These serverless platforms simplify infrastructure management and provide on-demand scalability for applications. However, companies like PubNub specialize in addressing specific developer pain points, particularly in real-time use cases. With its unique serverless environment, PubNub excels over generic serverless products exclusively in real-time scenarios.

PubNub's serverless functions offer incredibly low latency execution, making it ideal for real-time applications such as chat, GPS location tracking, IoT signaling, multiplayer games, and more. These functions, which automate the execution of application code in response to events, are easy to build and deploy, thereby reducing the time-to-market. Moreover, PubNub now supports JavaScript and TypeScript for function development, offering developers more flexibility.

If your use cases involve heavy computation, require languages that need OS access, and are not latency-sensitive, you might find the extensive serverless offerings from large cloud hosting companies like AWS, Azure, and Google to be more suitable. These providers support a wide array of programming languages including, but not limited to, Node.js, Python, Java, Rust, PHP, .NET (C#), Ruby, and more.

For a comprehensive comparison of PubNub Functions and AWS Lambda, check out our blog post which provides in-depth insights on choosing the right serverless provider for your business.

It's also worth noting that when it comes to serverless applications, security is a crucial aspect to consider. Rest assured, PubNub's serverless environment prioritizes data security, offering robust authentication mechanisms and secure API endpoints to safeguard your data.

In conclusion, whether you are a startup seeking a cost-effective serverless solution or an established enterprise looking to leverage the power of serverless architecture for mission-critical applications, understanding the strengths and capabilities of different serverless providers can help you make an informed decision.