BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Momento Topics: A Serverless Event Messaging System for Pub-Sub

Momento Topics: A Serverless Event Messaging System for Pub-Sub

Momento now offers Momento Topics, a serverless event messaging system that supports publish-subscribe communication patterns. This service is designed to provide a messaging pipeline for event-driven architectures. Subsequent feature releases will allow direct AWS Lambda invocations and change data capture events triggered from Momento Cache.

Momento aims to enable developers to write reliable and robust event-driven applications quickly. Their first product, Momento Cache, launched in 2022, is a serverless cache for database and application use cases that has been described by serverless advocate Alex DeBrie as "a cache for the 21st century—for the serverless, cloud-enabled era." Momento Topics is the second service from the Momento team and is designed to immediately deliver published messages to all current subscribers of a topic, after which they are discarded. Momento recommends this service for scenarios where low-latency message delivery is prioritized over occasional message loss. As messages are not stored indefinitely on Momento Topics, usage is billed against volumes of data moved via the service.

The key benefits of Momento Topics include a simplified pricing model with a 50GB free tier, configuration-free management of topics, and millisecond tail latencies at a large scale. To use Momento Topics, applications need to install the Momento SDK, which has varying levels of support across eight programming languages and frameworks, including Node.js, .NET, and Java. As Momento Cache backs Momento Topics, applications will need to connect to an existing cache instance via the SDK before publishing or subscribing. Below is a code snippet showing how to set up the client to publish in Node.js:

import {
   TopicClient,
   TopicPublish,
   Configurations,
   CredentialProvider,
 } from '@gomomento/sdk';


const momento = new TopicClient({
 configuration: Configurations.Laptop.v1(),
 credentialProvider: CredentialProvider.fromEnvironmentVariable({
   environmentVariableName: 'MOMENTO_AUTH_TOKEN',
 }),
});


const publishResponse = await momento.publish(cacheName, topicName, value);


if (publishResponse instanceof TopicPublish.Success) {
 console.log('Value published successfully!');
} else {
 console.log(`Error publishing value: ${publishResponse.toString()}`);
}

To subscribe, the code is similar, with the addition that the client needs to register a callback that can be triggered when new items arrive:

const response = await momento.subscribe(cacheName, topicName, {
   onItem: handleItem,
   onError: handleError,
});


function handleItem(item: TopicItem) {
   console.log('Item received from topic subscription; %s', item);
}


function handleError(error: TopicSubscribe.Error) {
   console.log(`Error received from topic subscription; ${error.toString()}`);
}

The Momento team has also announced plans to enhance the subscription functionality of Momento Topics with two features. The first, Executors, would allow Lambda functions to be directly invoked as subscribers to topics, while the second, Triggers, would allow subscriptions to be triggered based on changes to data stored within Momento Cache.

Momento Topics is comparable to AWS Eventbridge, Azure Event Grid, and GCP Eventarc, as it focuses on decoupled application integration via events. While it offers a similar serverless and low configuration overhead to other services, it differs with its dead-lettering/event delivery capabilities. Where the other services do not guarantee event delivery order and utilize dead-lettering, Momento Topics provides messages with sequence numbers and aims to enable the initialization of subscriptions from a checkpointed sequence number. Another key difference with Momento Topics is the number of publishers and subscribers it supports natively. While AWS Eventbridge, Azure Event Grid, and GCP Eventarc have integrations with their broader ecosystems, Momento Topics has only announced future integrations with AWS Lambda and Momento Cache.

Further information on how to get started with Momento Topics can be found on its documentation page.

About the Author

Rate this Article

Adoption
Style

BT