Live data from Hacker News

Ask HN: Options for handling state at the edge?

news.ycombinator.com

1–10 of 40 posts

Ask HN: Options for handling state at the edge?

#1
With Cloudflare workers able to be called single digit ms away from customers on much of the planet now, I wonder how I can keep state as close to the workers / lambdas as possible.

What are the options we have for handling state as the edge? What do you use in your business or service?

Re: Ask HN: Options for handling state at the edge?

#3
I recently had an opportunity to build an application on top of Lambda@Edge (AWS's equivalent of Cloudflare workers). The prevailing wisdom there was to make use of regional services, like S3 and DynamoDB, from the edge. That, of course, makes my edge application depend on calls to a larger, further away point of presence.

While it's possible to distribute state to many AWS regions and select the closest one, I ended up going a different route: packaging state alongside the application. Most of the application's state was read-only, so I ended up packaging the application state up as JSON alongside the deployment bundle. At startup, it'd then statically read the JSON into memory - this performance penalty only happens at startup, and as long as the Lambda functions are being called often (in our case they are), requests are as fast as a memory read.

When the state does need to get updated, I just redeploy the application with the new state.

That strategy obviously won't work if you need "fast" turnaround on your state being in sync at all points of presence, or if users can update that state as part of your application's workflow.

Re: Ask HN: Options for handling state at the edge?

#4
Just build a tiny application alongside an open source Varnish instance, and use it as a local backend. It's "free" if you have decent latency to the area of Internet you care about. For example, my latency is just fine to all of Europe so I host things myself.

If you want to go one step further you can build a VMOD for Varnish to run your workloads inside Varnish, even with Rust: https://github.com/gquintard/vmod_rs_template

Re: Ask HN: Options for handling state at the edge?

#5
I have used card database files before with success. https://cr.yp.to/cdb.html

Have your process regularly update the CDB file from a blob store like S3. Any deltas can be pulled from S3 or you can use a message bus if the changes are small. Every so often pull the latest CDB down and start aggregating deltas again.

CDB performs great and can scale to multiple GBs.

Re: Ask HN: Options for handling state at the edge?

#6
You just developed your application from the cache inwards, instead of the application outwards.

Now on to develop the actual application that will host/serve your data to said cache layer.

If you learn basic application architecture concepts, you won't be fooled by sales person lies again.

Re: Ask HN: Options for handling state at the edge?

#7
post #3

I recently had an opportunity to build an application on top of Lambda@Edge (AWS's equivalent of Cloudflare workers). The prevailing wisdom there was to make use of regional services, like S3 and DynamoDB, from the edge. That, of course, makes my edge application depend on calls to a larger, further away point of presence. While it's possible to distribute state to many AWS regions and select the closest one, I ended…

I think this is a really clear winner for something like Litestream, where you can have state far away but sync it locally with periodic syncs if you can live with 'small wait on startup' and 'periodic state updates'.

Re: Ask HN: Options for handling state at the edge?

#8
post #5

I have used card database files before with success. https://cr.yp.to/cdb.html Have your process regularly update the CDB file from a blob store like S3. Any deltas can be pulled from S3 or you can use a message bus if the changes are small. Every so often pull the latest CDB down and start aggregating deltas again. CDB performs great and can scale to multiple GBs.

I thought it was "constant database"? Is it indeed meant to mean "card database"?

Re: Ask HN: Options for handling state at the edge?

#9
post #3

I recently had an opportunity to build an application on top of Lambda@Edge (AWS's equivalent of Cloudflare workers). The prevailing wisdom there was to make use of regional services, like S3 and DynamoDB, from the edge. That, of course, makes my edge application depend on calls to a larger, further away point of presence. While it's possible to distribute state to many AWS regions and select the closest one, I ended…

We do something similar in Climatiq on Fastly's Compute@Edge. When building the application we load in a big chunk of read-only data in-memory, and serialize that memory to a file. When we spin up our instance, all we have to do is load that file into memory and then we have tons of read-only data in just a few ms.

Re: Ask HN: Options for handling state at the edge?

#10
I don't have a whole lot to say on this right now (very WIP), but I have a strong belief that git is a core tool we should be using for data.

Most data-formats are thick-formats, pack data into a single file. Part of the effort in switching to git would be a shift to trying to unpack our data, to really make use of the file system to store fine grained pieces of data.

It's been around for a while, but Irmin[1] (written in Ocaml) is a decent-enough almost-example of these kinds of practices. It lacks the version control aspect, but 9p is certainly another inspiration, as it encouraged state of all things to be held & stored in fine-grained files. Git I think is a superpower, but just as much: having data which can be scripted, which speaks the lingua-franca of computing- that too is a superpower.

[1] https://irmin.org/ https://news.ycombinator.com/item?id=8053687 (147 points, 8 years ago, 25 comments)

Post reply on HN