Insights

What is a Serverless Function? Cloud Computing Architecture

5 min read Darryn Campbell on Feb 7, 2024
serverless function feature.png

Serverless Functions Definition

Serverless architecture is a cloud computing model where the backend (server-side) provider manages the infrastructure, and the developer focuses solely on writing code. Serverless functions are single-purpose, programmatic functions 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. Serverless architectures if properly maintained by engineering teams ensure near-perfect uptime (>99.999 SLA / operational level), 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 cloud computing. It's not the cloud computing companies themselves creating these functions; it’s their busienss needs & customers.

What is the advantage of serverless functions and services?

Serverless functions and services simplify code maintenance, reduce hosting costs, and provide managed infrastructure, ensuring reliability. This approach is popular for code deployment, its quick, simple, and easily automated.

Need a serverless solution? Test it out for free here >

Examples of a serverless functions providers

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 using serverless functions and architectures?

Historically, monoliths have large, unified codebases, which require a full deploy of the entire platform for any commit (shipment/deploy) 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:

  • Will my servers respond to all client requests, with very low latency, regardless of each client's physical location?

  • Am I creating room for human error in my code deployment process?

  • Can my servers handle sudden increases in request volume without overloading?

  • Can my servers handle sudden increases in request volume without wasting lots of money?

  • Do I need to constantly monitor my app’s infrastructure? I sure do like sleeping 8 hours per night.

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

Serverless function code should be stateless to avoid inconsistencies across redundant instances. Cloud providers deploy these functions globally, ensuring low latency by running them close to end users. This backend architecture setup reduces latency for client-side requests and the cloud provider handles all networking logic.

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.

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 PubNub or Kubernetes, services can programmatically scale their infrastructure. 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

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 a unique set of services and capabilities.

Serverless Functions environment

Real-Time 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. There are different programming languages that are usable, depending on the cloud provider. 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 but expensive 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 low latency execution, making it ideal for applications such as chat, GPS location tracking, IoT signaling, multiplayer games, and more. Java Script Functions automate the execution of application code in response to events, are easy to build and deploy, thereby reducing the time-to-market.

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.

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.

Check comparison of PubNub Functions and AWS Lambda