Free up to 1MM monthly messages. No credit card required.
In one way or another, we’re often asked, “is PubNub Functions the same as AWS Lambda?”
Though Functions and Lambda are event-driven services and overlap with respect to elegant solutions that both services can support, that’s where the similarities end. The difference lays in what scenarios and use cases each solves, and in this post, we’ll break down the best uses for each technology.
Lambda allows an event trigger to invoke code, and/or another one of Amazon’s many services. For example, a Lambda function might be triggered when a social media stream is loaded into Kinesis, and the function generates trend data and writes to DynamoDB. This is all running within the AWS ecosystem, and the metric the user is billed by is compute time.
PubNub Functions are invoked specifically by PubNub real-time messages or via conventional HTTP requests. The PubNub Functions solution for NoSQL data storage is via a globally replicated KV Store. PubNub does not charge users based on their compute time or read/write throughput on a database. Users are charged per transaction, meaning once per Function event handler execution. So in the scenario of storing tremendous real-time data, a similar solution to Lambda can be implemented using PubNub Functions and the KV Store, but with a lower cost.
PubNub Functions are invoked whenever a PubNub real-time message is sent over the pub-sub network. This can be set to trigger on one or many channels within a user’s subscribe key. The pattern is meant to enrich an in-transit, real-time message with additional data, before it reaches each of its subscribers. PubNub Functions can also be invoked by a conventional REST API call. The processing scope is meant to be narrow and single purpose, like a microservice.
Lambda Functions are invoked by any Amazon service in an event-driven fashion using an AWS SDK. The pattern is meant to trigger other services and do computation on data as it is submitted. The data can then be accessed by other Amazon services in immediately.
The difference here is that PubNub Functions are primarily for in-transit data enrichment, while Lambda Functions are supposed to perform specific compute in an event-driven manner.
Lambda Functions require permissions to be granted to any other Amazon service that the developer wants to have invoke it using IAM.
Comparatively, PubNub Functions are invoked on the specific channel and subscribe key that a developer chooses. Any device with an internet connection that knows the subscribe key and channel for the Function can invoke the Function (unless PubNub Access Manager is active and provisions are not set).
A private message validation service can be implemented in a PubNub Function. With this in place, a client can send a message to a server using PubNub, and the Function can validate the integrity of the sender or message payload while it is in-transit from sender to receiver. Secret encryption keys can be stored and algorithms for crypto can be simply implemented inside the PubNub Function ecosystem.
Another example is a chat app message can be sent from one user in English and translated while in-transit to French using a PubNub Function and a language translation API, like Microsoft Translator or Amazon Translate.
Both services offer a place to deploy a codebase once, and the serverless backend globally distributes instances of the program automatically. This is an industry standard feature of FaaS (Functions-as-a-service). The developer does not need to think about building containers, load balancers, or performing several deploys to data centers around the world, every time changes are made to the code.
The code that a dev team deploys is automatically invoked by events that are directed to the Function trigger. The Function execution can fire other services within the AWS or PubNub environment, or any other third-party API.
Storage is offered within both platforms. PubNub Functions has the KV Store, a NoSQL database with read and write times under 3ms. AWS has DynamoDB for NoSQL storage which can be connected to Lambda Functions.
Both Lambda and PubNub have the ability to invoke other services within their own ecosystem. PubNub can use a Function for Publishing to other channels and also making grants in PubNub Access Manager. Lambda of course is able to trigger read/write to Redshift, Simple Email Service, ect.
Lambda is ideal for situations where processing power is necessary, and PubNub is ideal when real-time speed and state read/write is necessary.
PubNub has an open source catalog of already-written Functions that enable rapid integration of third-party services into the serverless execution flow.
Say you need real time text translation in a chat application. The BLOCKS Catalog already has a module for Watson Translation and AWS Translate that can be used to translate in-transit text, or in the form of a REST API. This feature allows a chat application to be made where a user sends text in english, and their partner receives the same message in Mandarin, in real time.
Any API can be connected to a PubNub Function whether it be custom, private, or public. Lambda Function examples are available on GitHub, however, the solutions are not as numerous, or as easy to integrate as the API partners referenced in the PubNub BLOCKS Catalog. PubNub Functions can be imported and globally deployed in just a few seconds.
Display real-time notification badges with PubNub and React Native to display important information and bring users back to your...
The concept of Digital Twins has evolved over the last two decades, however, one thing remains the same: the need for real-time...
Learn the ins-and-outs of PubNub message size and get a better idea of how many text characters fit in a single message.