Cloudflare TV

Using Momento with Cloudflare Workers

Presented by Khawaja Shams, Chris Price, Gift Egwuenu
Originally aired on 

Join Khawaja Shams CEO and Co-founder of Momento, Chris Price, Software Engineering Manager at Momento, and Gift Egwuenu, Developer Advocate Cloudflare as they demonstrate how to integrate Momento with Cloudflare Workers.


Transcript (Beta)

Hi everyone, welcome to the Cloudflare TV live segment. I am Gift, Developer Advocate at Cloudflare.

And in today's segment, we're going to be talking about Memento.

So using Memento with Cloudflare workers. With me today, I have two special guests and I'll allow them to do the honors of introducing themselves.

So over to you, Chris.

All right. Hi, my name is Chris Price. I'm a software engineer at Memento and I work on our developer ecosystem team.

So I work a lot with our client libraries and our integrations with cool other companies like Cloudflare.

And I'll let Khawaja introduce himself and talk a little bit more about our product.

Thank you, Chris.

Thank you, Gift. Hi everybody. My name is Khawaja Shams. I'm the co-founder and CEO at Memento.

My other co-founder is Daniela, who's not here today.

Chris is being humble. He actually runs our developer ecosystem team or maybe he is giving himself too much credit because he's technically a manager, not really.

I'm just kidding. Memento is a serverless cache.

You can think of us as a fast origin. We are a in -region cache inside of AWS and GCP that makes it really, really easy for people to get access to their data very, very quickly without dealing with any infrastructure.

So you just call create cache and you start doing gets and sets or dealing with advanced data structures without having to worry about the underlying infrastructure.

And the one thing that Memento is not is that it's not an edge cache.

So I and Chris and everybody at Memento are super excited about deeper integration with edge-based functionalities because a lot of our customers, when they think about caching, they think about the edge and they want to get access to a fast origin that's in region from their edge workers and marry them with their edge workers.

So it's been awesome to see this partnership between Cloudflare and Memento.

That's interesting. So I'm curious, what have you seen developers viewed with Memento in the ecosystem?

What kind of applications do you find?

Yeah. Sorry, I wasn't sure if you said integrations or applications. So, okay.

Applications. Yeah. Yeah. So people are building all kinds of really interesting things on top of Memento.

So we see a lot of gaming companies that love using Memento's publish and subscribe capability.

So Memento topics. You can build chat applications and high-scale notification systems in a matter of a few hours.

So there's a blog on our website where somebody was able to build a something that required 3.75 million subscribers in an afternoon.

And the really cool thing about Memento versus some of the other PubSub systems is that it's got the HTTP web server kind of baked in.

So you don't have to have Memento and then have a fan out layer on top of it.

You can connect your devices directly to Memento for this PubSub capability, which really simplifies the architecture.

The other one is customers that are trying to do large-scale machine learning and feature stores.

Being able to get to a million TPS with a system without having to worry about what the underlying infrastructure looks like is pretty neat.

So we see people doing that.

And then we also see customers like Wise Labs storing thumbnails on Memento as well.

Wise has got 10 million plus cameras and they use Memento to cache pictures of interesting things that might be going around that your security camera may be capturing.

Yeah, that's cool. That's pretty interesting.

All right. So I would be interested in seeing how Memento actually works.

So Chris, would you like to share your screen? Yeah, sure. So here we go. Can you see it all right?

Yeah. Okay. So this is the Memento console. So this is kind of the simplest place to get a quick sense of what all products we have and what capabilities you can do with them.

So the first screen you see here is just a list of all the caches that you've created in Memento, but you can go inside of a cache and you can do something like set a value for a key or just set this key to be the name foo and the value foo and we'll insert it.

And now in the get up here, we can get it.

This console screen is more for debugging or demo purposes, but you can imagine doing all of this stuff using just a couple of lines of code in whatever your favorite programming language is.

We also support different data types in here. So if I wanted to create a dictionary object instead of just a simple string object, I can do that.

And then when I insert that one, I get back the value. So then we have different APIs that allow you to read just like one field from a dictionary or set multiple fields in the dictionary, so on.

So fairly typical cache stuff for at least caches like Redis and things like that, where the collection data types are kind of one of the core primitives.

So we also on our console have a place where you can create API keys.

And when you create an API key, you can provide you can provide a scope for the token.

So if you wanted to give out a token to be used in a browser or something like that, you can create a token that only has like read access or read write access.

So it gives you a lot more control over which users that are interacting with your cache have which level of permissions.

And then one more thing I'll show in here real quick is our topics support.

Our topics is like our PubSub product. So it's a way that you can broadcast messages and then receive them from other subscribers.

So in this little demo screen that we have in our console here, if I just create a topic, call it topic, then it gives me these kind of two windows here.

On the left, I can see some example code that shows what it looks like to subscribe to a topic using Momentos SDKs.

And on the right, I can see what it looks like to publish messages to the topic.

And then I can publish some test messages here. So I can say hello. So and I can start a stream of messages over here.

This is just calling that publish API every n number of seconds.

And you can see that the subscriber here on the left is receiving them.

So these are some of the core products capabilities that we have.

And one of the ways that we were kind of excited about the opportunity to integrate with Cloudflare is in addition to being able to write code in your Cloudflare worker that would read or write values from a cache, which you would potentially do for performance optimization reasons, or just as a different way of sharing data between your application code and your Cloudflare worker code.

But you could also use this topic functionality, which would allow you to do something like when one of your Cloudflare Workers gets invoked, you could publish a message to a topic and then any other applications out there that were subscribing to that topic would see that message.

So there's all kinds of interesting integrations you can imagine setting up that way.

So those are kind of a super quick tour of some of the main capabilities that we have in the Memento console.

Awesome. This looks great. Thanks for sharing. And one thing I'd like to also highlight is how we've made the integration easy to work with, with our database integrations at Cloudflare, where we have enabled developers to be able to set up their connection seamlessly directly from the dashboard by selecting a database integration of choice, in this case, Memento.

So I'm going to show you like how this would work when you're using a Cloudflare Workers application and you want to create a cache in Memento.

So I'll go ahead and share my screen. So right here, I have a sample worker code.

Just to confirm, you can see my screen, right?

Yep. Okay. So right here, I have a sample worker code. And essentially what I'm doing here is I'm using the Memento SDK API to create and read from my cache.

Over here, I was able to create two different tokens that are required to connect to the Memento SDK, which is my API key as well as Online63, which is my API key as well as the specific cache that I would like to read from.

And just over here, within the fetch request, I'm setting some checks to see if the API key was actually defined, if it's not sent back an error.

And here is basically where everything happens, right, with the new cache clients where I'm setting the configuration, the credential provider, and the specific API key.

So with that, what I'm doing is just what you shared on the dashboard crease, I'm essentially creating a key and then sending that to the sample cache that I've created and then reading that back from the cache.

So if I go ahead and run this worker locally, by running npm start.

I also already because I'm running this locally, I already created a .dev.vas, which is equivalent of a .env file for saving the API key.

And then I have the cache, the Memento caching defined within my Wrangler configuration file.

So if I go ahead and open this, I'll just move my screen over here.

You can see I'm receiving a response back from the cache.

And just to see how this works also in the dashboard, the specific cache that I created is called workers.

And I am setting I'm setting the values here, first name, last name.

And what I'm doing also is getting back the value by calling clients to get the cache and the specific key.

And that's what happens here. The interesting bit I'll also like to show you is how easy for you to do the integrations seamlessly by adding the database integration directly from the dashboard.

So over here, where I have my worker, we have a new integration stab here where you can select any database connection you're trying to make.

In this case, Memento would be the one that I want to work with.

So to deploy my applications and, you know, set my API, normally you'd have to like do the whole setup yourself, collect the API key from Memento, add it to your environment just as I did it locally.

But here you just need to add the integration.

So I'll go ahead and click add integration. And then you have to go through some setup, which would enable you connect your account, your Memento account to allow Cloudflare have access to, you know, connecting to your cache and setting the API token.

So now that I've successfully connected to Memento, I would go ahead and select the specific region that I would like this to be.

I am in the EU region, so I'll go ahead and select EU West.

So what happens is you then get two keys created for you, two variables created for you, the Memento HTTP endpoints, and then the API key.

So I'll go ahead and add this integration.


I think something's happening where I think I've added this multiple times and then let me see.


So before now, I think I already added it. So maybe deleting it and re -adding it would work.

Because the API token is missing here.

So let me just see if that works. So heading back to the integration stab, I'll try to add the integration again.

So what's happening here is that it's actually connecting to Memento using your SSL token, creating an API key for you behind the scenes, right?

Yeah. Yeah, so that works.

What then happens is I now have the Memento API key as well as the HTTP endpoints added as the environment variables for this worker.

Okay, interesting.

So this is what I was saying before, when I was running into the thing, I will try to redeploy the worker to see if interesting thing is doing that will actually rewrites, like updates the variables that I just added.

Gotcha. Yeah. Okay, it works.

Good. It's all right. Yeah. Okay. Live demos, right? Yeah. Yeah. Because I was wondering why was that happening?

Okay. So essentially, what I showed is how you can actually connect Memento to your workers and to the dashboard using the database integration and creates like a cache to in this application, it's pretty straightforward setting, creating a key, and then listing it back from application.

But there are so many other things that you could do with the cache, like Kairaja explained earlier, there are so many different applications you could use.

And the power of Cloudflare having data centers around several regions, it would eventually help with low latency for your users switching, coming from different parts of the world or trying to access your applications from different parts of the world.

So I will stop sharing my screen. Yeah.

So the interesting thing about the integrations that I've seen is this gives developers access to work with Memento.

So in this case with Memento, I am very curious what the different use cases you've seen.

So for example, you have the web SDK, you have the HTTP endpoints, how it enables developers to connect to Cloudflare Workers.

What do you think about the integration and what do you see like people do with this?

Yeah. You want to go first, Kairaja? No, go ahead. Okay. I can follow.

Cool. So I mean, definitely one of the first things that comes to mind is if you have a page that you need to load that has some kind of expensive database query going through it, then being able to have your end users directed to the Cloudflare API and then have it the first time that that worker gets invoked and makes the expensive database query, saving the result off into a Memento cache will mean that subsequent executions of that worker would be much quicker, obviously.

Another thing that we think could be powerful about this integration is if you have your own web service, your own web application that is processing a lot of data in real time and needs to send out updated values from the computations that it's doing in a way that would then be accessible to the Cloudflare Workers, your main service architecture could be periodically updating a value in the Memento cache.

And then when a request comes through Cloudflare and it's just reading that value in from the cache, you're able to kind of get more like real -time synchronization of data between the different parts of your system.

And then as I mentioned when I was showing my screen share a little bit earlier, I'm really excited about our topics support, the PubSub support.

We're starting to really think about new use cases where we're doing like event-driven applications where something that happens that causes as users are invoking Cloudflare Workers, having a way to use that as a trigger to an event by publishing a message to a Memento topic and then again having some of your back-end infrastructure subscribe to that topic to see the events that are coming in as your users are hitting the triggering the worker and react to those in various different ways.

Updating metrics or updating information in your database, etc.

So those are just a handful.

I bet Quazha has some more. Yeah, I think in general, we see a lot of gaming companies wanting to have edge-aware routing, for instance, to be able to get the data into the hands of customers fast.

But sometimes you don't have all the information available at the edge and you do end up going back to the end database.

You don't want to make your really fast edge worker be waiting for a slow database, so caching from the database works.

But there's a whole lot of other things that we do beyond just key value.

We can have complex data structures like leaderboards and so forth that are available in the cache directly, so there isn't even a database lookup in case of a cache miss.

We can be a primary source of the most up-to-date data, like what is the latest score for a football game or in a particular game that a customer, a set of players are playing.

Things that have changed, they can be sorted in a list or a sorted set or a dictionary in Memento as well.

So getting access to that rich layer of data structures available quickly when there is a miss on the edge side is, I think, the backbone of the applications that we think are feasible.

Well, thank you. That's really interesting and I'm glad to hear the different use cases that you find useful for this integration.

Well, thank you so much for coming on.

If there is any additional resources you find that people would be interested to look up Memento, especially to learn about topics like you shared, I would add that to the stream once the recording goes live so people can check it out.

But it was really nice to have you both join me to talk about Memento and Cloudflare Workers.

Yeah, you too. Thank you. Thank you for having us and for all the integration work and the partnership.

Really appreciate it. Sounds good.

Thank you. And with that, we'll end the stream. Thank you everyone for joining us.

Hi, we're Cloudflare. We're building one of the world's largest global cloud networks to help make the Internet faster, more secure, and more reliable.

Meet our customer, BookMyShow. They've become India's largest ticketing platform thanks to its commitment to the customer experience and technological innovation.

We are primarily a ticketing company. The numbers are really big. We have more than 60 million customers who are registered with us.

We're on 5 billion screen views every month, 200 million tickets over the year.

We think about what is the best for the customer.

If we do not handle customers' experience well, then they are not going to come back again.

And BookMyShow is all about providing that experience.

As BookMyShow grew, so did the security threats it faced. That's when it turned to Cloudflare.

From a security point of view, we use more or less all the products and features that Cloudflare has.

Cloudflare today plays the first level of defense for us.

One of the most interesting and aha moments was when we actually got a DDoS and we were seeing traffic burst up to 50 gigabits per second, 50 GB per second.

Usually, we would go into panic mode and get downtime. But then all we got was an alert and then we just checked it out and then we didn't have to do anything.

We just sat there, looked at the traffic peak and then being controlled.

It just took less than a minute for Cloudflare to kind of start blocking that traffic.

Without Cloudflare, we wouldn't have been able to easily manage this because even our data center level, that's the kind of pipe, you know, is not easily available.

We started for Cloudflare for security and I think that was the aha moment.

We actually get more sleep now because a lot of the operational overhead is reduced.

With the attack safely mitigated, BookMyShow found more ways to harness Cloudflare for better security, performance, and operational efficiency.

Once we came on board on the platform, we started seeing the advantage of the other functionalities and features.

It was really, really easy to implement HTTP2 when we decided to move towards that.

Cloudflare Workers, which is the, you know, computing at the edge, we can move that business logic that we have written custom for our applications at the Cloudflare edge level.

One of the most interesting things we liked about Cloudflare was everything can be done by the API, which makes almost zero manual work.

That helps my team a lot because they don't really have to worry about what they're running because they can see, they can run the test, and then they know they're not going to break anything.

Our teams have been, you know, able to manage Cloudflare on their own for more or less anything and everything.

Cloudflare also empowers BookMyShow to manage its traffic across a complex, highly performant global infrastructure.

We are running on not only hybrid, we are running on hybrid and multi -cloud strategy.

Cloudflare is the entry point for our customers.

Whether it is a cloud in the backend or it is our own data center in the backend, Cloudflare is always the first point of contact.

We do load balancing as well as we have multiple data centers running.

Data center selection happens on Cloudflare.

It also gives us fine-grain control on how much traffic we can push to which data center depending upon what, you know, is happening in that data center and what is the capacity of the data center.

We believe that, you know, our applications and our data centers should be closest to the customers.

Cloudflare just provides us the right tools to do that. With Cloudflare, BookMyShow has been able to improve its security, performance, reliability, and operational efficiency.

With customers like BookMyShow and over 20 million other domains that trust Cloudflare with their security and performance, we're making the Internet fast, secure, and reliable for everyone.

Cloudflare, helping build a better Internet.

My name is Sam Ray.

I'm a VP of Product here at Cloudflare. I joined Cloudflare in June of 2018.

In the last five years, I've had an opportunity to work on nearly a dozen different products, from our domain registrar to our access control product.

But today, I spent all of my time thinking about how can we use Cloudflare's network to help teams and enterprises really of any size keep their organization safe and connected.

My favorite part of my role at Cloudflare is other than getting to work really closely with customers, is as a product manager and as part of the product team, we have the opportunity to work with teams and team members from across the entire organization.

Because our job really is asking ourselves, how can we work together as an entire Cloudflare team to help our customers solve more problems every day?

I'm Sam, and this is my life at Cloudflare. My name is Kyra, and I'm an office coordinator at Cloudflare.

The role itself is very varied from day to day.

I come into the office and make sure that everything is prepared for the employees, that the area is clear and works for the teams and the different jobs they have to do, help out with events on site, internal and external, make sure our fire marshals are organized and working closely with the management of the building which our office is based in.

So it's a very varied role.

What I enjoy about working in Cloudflare is honestly the people. My job is very people-based.

The thing I enjoy the most is making the environment lovely for the employees and the grateful attitude that I get from the employees for giving them a nice environment.

My name is Kyra, and this is my life at Cloudflare. SageGroup is a leading technology company that helps businesses to thrive.

We have a global footprint.

We service millions of customers, entrepreneurs worldwide. The key security challenges in the industry in cybersecurity, they have been about the uprise of criminal groups.

They are becoming more professional with more capabilities, which is causing the companies to have to respond to those threats.

Cloudflare has a number of solutions available for a technologist, so it acts almost like a Swiss army knife.

Cloudflare bot management provides the ability of identifying what's human traffic versus automated traffic.

It reduces a significant amount of concern around web scraping, around multiple automated attacks that people could launch against your website.

Cloudflare Workers, it's a powerful way for you to delegate the computes to the edge, and that has brought immense flexibility for our engineering teams.

One of the great things about Cloudflare and how it differentiates itself from other vendors is the Cloudflare Zero Trust approach.

In many cases with other vendors, most likely you'd have to overlay those capabilities like reverse proxy, links to a web application file, links to logging analytics.

While with Cloudflare Zero Trust, many of those capabilities are already kind of backed together for you, which means that you don't have to add complexes to your environment.

Sage and Cloudflare, we have a long history, but our relationship become much stronger over time.

Cloudflare has this amazing ability to kind of create capabilities that speaks to the operations team, but also speaks to the security profession, and not many companies can achieve that.