How it works - Momento Serverless Cache
On this page, you will learn about the concepts specific to using Momento Serverless Cache in your application. These concepts apply across languages -- while Momento has supported SDKs for Golang, JavaScript, Python, Java, and .NET, the concepts described on this page are applicable to all of them.
In crafting Momento Serverless Cache, we've focused on two things: simplicity and speed. Every decision we make is in service of these two goals. In describing the Momento Serverless Cache concepts below, we will also explain how these concepts make it easier or faster for you as a user.
On this page, we'll cover two main aspects of working with Momento Serverless Cache:
The CacheClient object and developing with Momento Cache
In every Momento SDK, you will be using a CacheClient object to interact with the Momento Cache service. The CacheClient object will provide credential management and efficient interaction with the Momento API.
For more info on how to get started with the CacheClient, see our Momento SDK page.
A CacheClient instance can interact with both the control plane and data plane APIs in Momento Cache. Let's take a look at each of these.
Control plane: simple, efficient cache management
The Momento Serverless Cache control plane API is the API you will use to manage your caches overall. You can use the control plane API to create a new cache, list existing caches, or delete an unwanted cache.
When you hear 'control plane', you might think 'slow, management operations.' But that's not the case here -- Momento has been designed to quickly and efficiently manage caches within your account. You won't fire a command to create a cache and wait for the cache to be created in the background. With Momento, the cache is created synchronously, within a second. Your cache will be ready to go by the time your request to create it has returned.
Each cache in Momento Serverless Cache is isolated from other caches, and there's no technicel limit on the number of caches you can have in your account, but there are guardrails in place in the form of service limits. This means you can have dedicated caches for each environment for your application or even each deployed branch in your Continuous Integration/Continuous Delivery (CI/CD) system.
Data plane: performant cache interactions
The Momento control plane is very useful, but data plane operations are where the action is. The data plane API refers to operations that actually interact with the data in your cache(s). It's designed to be blazing fast -- most data plane operations take less than 1-2 milliseconds from the client's perspective.
The data plane includes the standard "set" and "get" cache functionality allowing you to write and retrieve a cache entry. You can also use the multi-get and multi-set commands to process multiple cached entries in a single request.
Interacting with the Momento Serverless Cache API
The SimpleCache object will be your main way of interacting with the Momento Serverless Cache API. Let's talk a little bit about what is happening under the hood. We'll discuss the authentication mechanism, the communication format, and the networking configuration for the Momento API.
Authentication token
Your SimpleCache object will use an authentication token when communicating with the Momento Serverless Cache service. This token is a JSON Web Token (or "JWT") that contains signed account information to authenticate you when making cache requests. It also includes information like the hostname of your cache instance, which helps the SimpleCache object to make more efficient requests to the Momento service.
You will receive the Momento authentication token when signing up for the Momento service. To get your Momento authentication token and begin using the Momento service, follow the quickstart here.
gRPC
Momento is a remote cache using a client-server model. Because of this, your SimpleCache client will need to communicate with your remote Momento cache. To facilitate this communication, Momento could use any number of communication methods, from a JSON API over HTTP to a custom-built RPC protocol.
The SimpleCache client object uses gRPC to communicate with the Momento service. gRPC is a popular open source remote procedure call (RPC) framework developed at Google for fast, efficient communication. When using gRPC, you define the RPCs you want to expose and the data structures you will use in a .proto file. This .proto file is then used to build the client and server implementations of your service.
There are two main benefits for you of using gRPC as a Momento user.
First, gRPC is fast. You may be familiar with using JSON-based REST APIs for interacting with other services. While this method is flexible, the plaintext format of the message results in a larger message size and slower performance. Conversely, gRPC uses protocol buffers by default to exchange messages between the client and server. Protocol buffers will serialize your data into a more efficient binary format, allowing for faster transport plus faster serialization and deserialization of your data. When you are using a cache like Momento, this additional speed is critical.
Second, gRPC has cross-language support. You can use the .proto files to quickly generate clients in a large number of supported languages. While this doesn't directly help you as a Momento user, you indirectly benefit by quickly receiving new features in your language of choice. The Momento team can generate base clients across languages, lowering the burden of maintaining SDKs for each language. We will craft a consistent, language-specific interface on top of the generated code for each language, but the baseline work of interacting with the Momento service is much lower.
gRPC is supported by all languages for which there is a Momento SDK. For most of these languages, you do not need to know that Momento is using gRPC -- all the dependencies and gRPC communication are handled for you by the Momento SDK. For special concerns about using the Momento Python SDK in AWS Lambda, check out our guide on using Momento in AWS Lambda.
Networking
As noted above, Momento cache is a remote service from your application, and thus we need to think about the networking infrastructure to connect your application to the Momento service. In keeping with our core principles, Momento offers two networking mechanisms for interacting with your cache: the default configuration, and an advanced configuration.
Default networking
By default, your SimpleCache client will connect to a publicly accessible endpoint for the Momento cache service. There are two main benefits to the default networking setup.
First, it is simple. You can get started with Momento and start interacting with your cache in as little as five minutes right from your laptop. You don't have to mess with complicated network configuration to benefit from a cache in your application.
Second, it works well with serverless applications. Many serverless applications prioritize using services that are available using HTTPS rather than connection models that require a private VPC to control access. Part of this is due to the initial complexity and latency around using Lambda functions within a VPC, but part of it is due to the reduced complexity of avoiding complex network configurations.
If these benefits appeal to you, the default networking setup is perfect for you.
Advanced networking
In addition to the default networking setup, Momento provides an advanced networking configurations that allows for an optimal path between your VPC and the Momento VPC depending on what is best for your application. We can currently support both VPC Endpoints and VPC peering in AWS.
These are good options for your workloads if you need to keep the traffic over private addresses for compliance or if you have extreme bandwidth or latency requirements. If you're interested in using a VPC Endpoint or VPC peering with your Momento cache, please contact us to learn more and get your account approved to try out.
Conclusion
On this page, we learned the basic concepts of working with the Momento SDK and API. If you want to get started using Momento, check out our getting started guide.
If you want to learn more about caching strategies and how to think about caching, check out our resource on caching strategies and patterns.