Run Your Custom Code on Our Infrastructure with Functions v2
PubNub Functions is a serverless edge-processing solution for developers building event-driven and real-time apps. It lets you insert business logic into your event-processing pipeline or leverage pre-built integrations to transform, re-route, augment, filter, and aggregate messages, as well as run code triggered by user presence events, and much more. Functions have been a cornerstone of the PubNub platform for years. Now, for the first time since their launch, we're introducing major updates that enhance features and elevate the developer experience.
What is PubNub Functions?
PubNub Functions is a serverless developer tool consisting of:
PubNub-managed infrastructure distributed across our global Points of Presence (PoPs) with autoscaling and redundancy capabilities
REST API for smooth implementation in any given development flow
A dashboard in PubNub Admin Portal including code editor, versioning, deployment management, and debug console
Why Do You Need PubNub Functions?
PubNub Functions allows users to run custom code directly within the PubNub network, enabling in-stream data manipulation without having to set up and maintain any infrastructure. It allows for isolated pieces of business logic that can be triggered by events such as messages, presence updates, or custom triggers, allowing for tasks like data filtering, content moderation, and message enrichment to occur on the fly.
For companies building software, PubNub Functions provides the flexibility to implement custom logic seamlessly within PubNub’s ecosystem, enhancing customer experiences while reducing costs and operational risks. By offloading business logic to PubNub, you eliminate downtime, scalability, and compliance concerns while benefiting from a pay-as-you-go pricing model. Edge execution ensures ultra-low latency for responsive user interactions, enabling real-time features like moderation and translation that elevate customer satisfaction. Additionally, edge processing optimizes data handling, reducing storage and transmission costs.
For developers, PubNub Functions streamline application development and accelerate time-to-market by providing pre-built integrations, robust logging, and a debug console—offering complete tooling for code delivery, testing, and deployment.
What’s New in V2
The new version of PubNub Functions adds a few really useful and highly requested features including:
Versioning - all functions now have revisions
Rolling updates - deploying function updates doesn’t cause downtime anymore
Public APIs - REST APIs to manage your KV, secrets, and more
Multiple deployments for one keyset - one function revision can be used within multiple keysets
Where PubNub Functions Stands Out
PubNub Functions is a comprehensive, serverless solution that delivers low-latency processing directly within the PubNub network—eliminating the need for external services. Unlike many competitors, which rely on third-party integrations such as AWS Lambda or Azure Functions, PubNub Functions provide on-the-fly (synchronous) processing, allowing developers to modify messages and events before delivering them to subscribers—critical for use cases like real-time content moderation and translation.
PubNub-managed infrastructure eliminates the operational complexity and dependency on external services, offering basic 10x auto-scaling on the lowest hardware tier without any cold starts, which are common in serverless solutions. Additionally, PubNub provides pre-built integrations and distributed edge processing through our global Points of Presence (PoPs), ensuring ultra-low latency and real-time responsiveness. With an intuitive UI for fast prototyping, debugging, and deployment, PubNub empowers developers to create and manage robust real-time applications faster and more efficiently than competitors who rely on external services that lack the same level of integration and control.
Common Use Cases for PubNub Functions
Asynchronous Use Cases for PubNub Functions
Asynchronous functions allow developers to process events after they’ve been handled by PubNub, making them ideal for tasks that don’t need to affect the real-time user experience but still need to be processed reliably and efficiently.
Common Asynchronous Use Cases:
Integration with External APIs: Trigger actions like sending data to third-party systems (e.g., CRM or customer support platforms) after an event occurs. PubNub Functions can feed data directly from your Pubnub network to modify it, encrypt it ifneeded, and call external services such as OpenAI for AI-based content analysis or SendGrid for email notifications.
Notifications: Send asynchronous notifications such as email, SMS, or push notifications after a specific event has occurred (e.g., a user joining a channel or sending a message).
Geolocation Updates: Process and store geolocation data from devices or users in real-time, triggering actions like sending personalized location-based offers or tracking user behavior without interrupting real-time communication.
Synchronous Use Cases for PubNub Functions
Synchronous (aka on-the-fly) functions are designed to run before events are processed by PubNub, allowing modifications to messages or events to be made in real-time. These use cases are ideal for tasks that must occur instantly to ensure high application responsiveness.
Common Synchronous Use Cases:
Real-Time Content Moderation: Automatically scan and filter out inappropriate content in messages before they reach subscribers. For example, detect offensive language or block harmful content in chat messages.
Data Enrichment: Enhance messages with additional information before they’re delivered to clients, such as appending user metadata or enriching messages with dynamic data (e.g., real-time stock prices or weather data).
In-flight Translations: Provide real-time language translation for messages in multilingual chat applications, allowing users from different regions to communicate seamlessly in their native languages.
Custom Message Routing: Route messages to specific users or groups based on dynamic criteria. For example, route high-priority messages to admins or direct specific alerts to designated channels in a gaming or financial app.
Most importantly PubNub Functions are available to all users, including free accounts. If you’d like to try them out yourself, just go to your account at admin.pubnub.com/functions.