14 ms·
Netlify Edge Functions: A new serverless runtime powered by Deno
- mfsch 4y agoDoes anyone know how those compare to regular Netlify Functions, other than running on the edge nodes? The main difference I’ve found is that they have much stricter CPU time budgets, but it seems to me that the use cases overlap quite a bit.
- AaronO 4y agoAaron from Deno here, happy to answer any questions you may have !
- robertlagrant 4y agoThanks! Any useful pros and cons vs Cloudflare Workers?
- tppiotrowski 4y agoLooks like it comes with Typescript support
- forty 4y agoAnything running JS comes with some TS support, you just have to transpile it before releasing :) I'm not sure why shipping the transpiler on the production server rather than keeping it in your CI is a good idea, but I think that's what Deno is doing.
- tppiotrowski 4y agoTrue, but one feature I enjoy about Cloudflare workers is that I just edit them in the browser, even on devices without nodejs installed.
- paulgb 4y ago> I'm not sure why shipping the transpiler on the production server rather than keeping it in your CI is a good idea, but I think that's what Deno is doing. IMHO, the decoupling of build step and runtime step in JavaScript was a terrible mistake. I've wasted hours just trying to find tsconfig settings that are compatible with the other parts I'm using. Shipping a transpiler with a known-good configuration alongside the runtime forces everyone to write their packages in a way that are compatible with that configuration, instead of creating a wild west. The current state of modules and npm reminds me a bit of the bad old ”php.ini” days, where you would have to make sure you enabled the language features enabled by the code you wanted to import. What a mess.
- forty 4y agoI understand that it might be a problem for browser target, but nodejs is pretty easy to target (at least I never had anyissue). Also speaking of wild west, Deno did not even manage to have their TS be the same as everyone else, as apparently they do import with .ts file extension, while everyone else is using .js. I feel like this would be creating more mess than fixing anything...
- oefrha 4y ago> I've wasted hours just trying to find tsconfig settings that are compatible with the other parts I'm using. Deno only “solves” that problem by not having a legacy ecosystem, and that’s only if you stick to the happy path of only using modules with first class Deno support. If you try to tap into the vast Node ecosystem, where Deno’s lacking, through e.g. esm.dev, you can waste hours just as easily. Even packages that claim Deno support sometimes have minor problems.
- hobo_mark 4y agoWorkers can have persistent storage attached to them (as a KV store), I can't see whether this has anything similar.
- agrippanux 4y agoAlso Workers can talk to Durable Objects which is super nice
- robertlagrant 4y agoYes, and I love the minimal pricing of both. Just paying for real compute time; even calling an API pauses the pricing while it waits for a response.
- robertlagrant 4y agoYes - that is really good.
- bobfunk 4y agoOne of the big reasons for going with Deno is that it's an open runtime closely based on web standards. You can download the open source Deno Cli and all code written for our edge layer will run exactly the same there. As more and more front-end frameworks starts leaning in on running part of their code at the edge, we felt it was important to champion and open, portable runtime for this layer vs a proprietary runtime tied to a specific platform.
- irq-1 4y agoCloudflare uses v8 and the client is open: https://github.com/cloudflare/wrangler https://github.com/cloudflare/wrangler
- robertlagrant 4y agoHm yes, the fact I can't run Cloudflare Workers somewhere else is a worry. Fair point.
- ignoramous 4y agoIs Netlify running Deno on their edge and not on Deno.com Deploy's? Is this also what Slack, Vercel (?), and Supabase do?
- lucacasonato 4y agoNetlify and Supabase use Deno's infrastructure for code execution (https://deno.com/deploy/subhosting https://deno.com/deploy/subhosting). Vercel hosts their edge functions on Cloudflare (nothing to do with Deno). Slack's Deno runtime is hosted on AWS.
- teleclimber 4y agoAre you willing to talk a bit about how Deno Deploy works internally? I think you have an internal build of Deno that can run multiple isolates (unlike the CLI, which basically runs one). How do you limit the the blast radius in case of a vuln in Deno? Kenton Varda did a pretty great writeup on CF worker security [0]. Would love to see Deno Deploy do something similar. [0] https://blog.cloudflare.com/mitigating-spectre-and-other-security-threats-the-cloudflare-workers-security-model/ https://blog.cloudflare.com/mitigating-spectre-and-other-sec...
- lucacasonato 4y agoWe probably will eventually. A talk like this takes a _lot_ of time to prepare though, so it's not on the top of our priority list. But it will happen eventually. The TLDR is that Deno Deploy works pretty similarly to CFW in that it can run many isolates very tightly packed on a single machine. The isolation strategy differs slightly between CFW and Deploy, but both systems make extensive use of "defense in depth" strategies where you minimize the blast radius by stacking two or more defenses against the same issue on-top of each other. That makes it _much_ more difficult to escape any isolation - instead of breaking out of one sandbox, you might have to break out of two or three layers of isolation. These levels of isolation could happen at different layers. For example network restrictions could be initially restricted by an in-process permission check, then additionally a network namespace, and finally a routing policy on the network that the machine is connected to. Imagine this, but not just for network, but also for compute, storage, etc.
- simonw 4y agoQuestion about https://edge-functions-examples.netlify.app/example/rewrite https://edge-functions-examples.netlify.app/example/rewrite export default async (request: Request, context: Context) => { return context.rewrite("/something-to-serve-with-a-rewrite"); }; I'm surprised that the function is async but context.rewrite() doesn't use an await. Is that because the rewrite is handed back off to another level of the Netlify stack to process?
- lucacasonato 4y agoActually `context.rewrite` returns a `Promise<Response>`. The `async` isn't necessary here, but it also doesn't particularly hurt. You can return a `Promise` from an async function no problem.
- glenjamin 4y agoSince it's being returned it doesn't really matter whether `.rewrite()` is returning a promise or not. `return await x` is mostly equivalent to `return x` within an async function.
- seniorsassycat 4y agoPromises are flat, so if a async function or promise callback returns a promise the result is just a promise, not promise<promise>. Using async for functions that do not use await is still a good idea because thrown errors are converted to rejected promises. `return await` can be useful because it's a signal that the value is async, causes the current function to be included in the async stack trace, and completes local try/catch/finally blocks when the promise resolves
- rektide 4y agoHow many Deno instances might an edge server run? Does each tenant have an instance or is there multi-tenancy? What interesting tweaks have you made making a cloudified offering of Deno tailored for http serving?
- AaronO 4y agoWe're building a highly multi-tenant "isolate cloud" (think VMs => containers => isolates, as compute primitives). The isolate hypervisor at the core of our cloud platform is built on parts of Deno CLI (since it has a modular design), but each isolate isn't an instance of Deno CLI running in some kind of container. Isolate clouds/hypervisors are less generic and thus flexible than containers, but that specialization allows novel integration and high density/efficiency.
- the_common_man 4y agoThis is a new concept for me, what is the use case for edge functions?
- valbaca 4y agoThe first link in the article points to this: https://www.netlify.com/products/#netlify-edge-functions https://www.netlify.com/products/#netlify-edge-functions How to use them Drop JavaScript or TypeScript functions inside an edge-functions directory in your project. Use cases Custom authentication, personalize ads, localize content, intercept and transform requests, perform split tests, and more.
- nawgz 4y ago> Use cases > A bunch of server functionality Why is that the use case? I don't see how an edge function can be faster than a centralized server endpoint if it has to reach out to literally any other component of the system involved in auth / persistence
- FinalBriefing 4y agoIt's just serverless architecture. It may not fit for every project. We use the concept to add meta tags to our client-side-rendered webapp for search indexing. We can decouple our client app from our server and deploy each separately. We use "serverless functions" to add some meta tags that need to be added server-side.
- nawgz 4y agoI mean, it's incredibly easy to deploy client apps separately from the server in a lot of ways To me, the only value I see for Edge compute is when some chunk of data requires processing going one way across the network, and that processing can be done entirely locally. I suppose what you describe with the meta tag qualifies in this case, otherwise I think serverless architecture looks like a pretty sweet deal for the cloud companies promoting it.
- 4y ago
- lewisjoe 4y agoThis is great news. I'm really rooting for a successful trend of Serverless runtimes, mainly as a weapon against rising cloud deployment costs. While the general trend today is to back the serverless environment with Javascript runtimes (Cloudflare runs its edge on top of V8, Netlify uses deno, most other serverless runtimes use nodejs), I'm optimistic that WebAssembly will take over this space eventually, for a bunch of reasons like: 1. Running a WASM engine on the cloud means, running user code with all security controls, but with a fraction of the overhead of a container or nodejs environment. Even the existing Javascript runtimes, comes with WebAssembly execution support out of the box! which means these companies can launch support for WASM with minimal infra changes. 2.It unlocks the possibility of running a wide range of languages. So there’s no lock-in with the language that the Serverless provider mandates. 3.Web pages that are as ancient as the early 90s are perfectly rendered even today in the most modern browsers because the group behind the web standards strive for backward compatibility. WebAssembly’s specifications are driven by those same folks - which means WASM is the ultimate format for any form of code to exist. Basically, it means a WASM binary is future proof by default. I've published my (ranty) notes on why Serverless will eventually replace Kubernetes as the dominant software deployment technique, here - https://writer.zohopublic.com/writer/published/nqy9o87cf7aa789ba49419eac167d0c34cfcb https://writer.zohopublic.com/writer/published/nqy9o87cf7aa7...
- electroly 4y ago> a fraction of the overhead of a container I mean, only in theory or when looking at it from the right angle, right? Or are you only comparing against JavaScript (unclear)? WASM is still much slower than native code. Containers spend most of their time executing native code; the "overhead" of containers is at the boundaries and is minor compared to the slowdown by moving from native code to WASM. In the future WASM may approach native performance, but it's not there now. I'm 100% certain that transitioning my native-code-in-containers workloads to WASM would be slower, not faster.
- teleclimber 4y agoEdge functions are typically run intermittently, with their runtime stopped to free up resources between runs. Therefore a big factor is startup and shutdown speed. Containers are pretty bad there. Deno is better, and WASM is unbeatable, especially with things like Wizer[0]. [0]https://github.com/bytecodealliance/wizer https://github.com/bytecodealliance/wizer
- ajdegol 4y agoGreat stuff! Well done!!
- wizwit999 4y agobig-time red flag that they're using deno's infra... wouldn't trust that
- undefined_void 4y agocare to elaborate?
- carnitine 4y agoWhy?
- Tajnymag 4y agoDeno is an offline runtime. Similar to nodejs. Not an infrastructure.
- wmf 4y ago
- dbbk 4y agoI would love to jump over to something like Vercel or Netlify Edge, but maddeningly none of these platforms give you control over the cache key. I have pages that are server-side rendered with Cache-Control headers, but because our visitors come with unique tracking params on the end of their URL (e.g. from Mailchimp or Branch), we would essentially have no cache hits. It seems the only way to have control over this is to write your own Cloudflare Workers. There must be a better way? I can't imagine this is an infrequent problem for people at scale.
- bobfunk 4y agoSo far Netlify Edge Functions runs before the cache layer, so you can actually use a minimal function to rewrite the URL to remove all unique params, etc, and then let it pass through our system to a Netlify Function which runs behind our caching layer. For anything you can do at build time as a static HTML pages we already strip query parameters from cache keys.
- dbbk 4y agoInteresting, thanks... do you have any docs on how we might achieve this with Next.js? Am I right in thinking we would have essentially a custom Edge Function first that handles query params, and then a second Edge Function that renders the Next app?
- ascorbic 4y agoI work at Netlify on framework integrations. Next has beta support for running the whole app at the edge, and Netlify supports that. If you create you own custom edge functions they will run first, so you can do just that. You can also run Next "normally" (i.e. in the node-based Netlify Functions) and run your own edge functions in front of that. In those you can modify the Request in any way you'd like, before passing it on to the origin.
- dbbk 4y agoYeah I'm very intrigued by running the whole app on the edge (in their Edge Runtime). This sounds pretty promising. I'll take a dive and see if I can get it working, thanks for the tip!
- deleted 4y ago[deleted]
- TobyTheDog123 4y agoNetlify pricing has always been confusing to me, but I'm not entirely sure why. I guess I'm more accustomed to pay-as-you-go in this space (CFW) than tiered plans (Netlify bundles their features into starter/pro/business). It seems that the free plan is 3M invocations/mo, starter is 15M/mo, and business is 150M/mo, but there aren't any ways to increase those limits (business says to contact them for higher limits). Personally I'd prefer true pay-as-you-go without hard limits, even if it's a bit more expensive. To me the point is to sign-up-and-forget-it without having to worry if I'm within those limitations.
- realmod 4y ago> Personally I'd prefer true pay-as-you-go without hard limits, even if it's a bit more expensive. To me the point is to sign-up-and-forget-it without having to worry if I'm within those limitations. Sure, if you can set a max budget. Otherwise, you'd constantly have to worry about the unbounded cost.
- mavsman 4y agoDifferent strokes for different folks. This has been one of the big knocks on AWS, that a poor little old lady can setup a "free" AWS account then when her website (and accompanying Lambda function) goes viral she gets hit with a $100k bill from uncle Jeff.
- rmbyrro 4y agoWould the Lady prefer to let her site go down? I don't understand this way of thinking. One of the main benefits of serverless is scalability, peace of mind for precisely when you go viral. If you're doing something good, especially if you're selling something good, all you want is to go viral. And of you went viral, you don't mind paying the AWS costs, which should be tiny compared to your revenue. Just need to care about your unit economics.
- yurishimo 4y agoSure, but I think the GP was referring to a situation where revenue doesn’t match the traffic. Imagine the grandma scenario. Let’s say that she cooks and sells artisanal jams and jellies. With the help of her granddaughter, she creates a TikTok that goes viral. Her web store immediately sells out, and the traffic from the video hammers her website. She cannot react fast enough to enable back orders and so most of those visits go to waste. Putting aside the technical absurdities (why is she hosting on a lambda, etc), in this scenario, grandma is up a creek. If this scenario were real, I would feel really bad for the grandma with a huge bill and not enough revenue to cover it, but I would be livid at whatever imbecile decided to set her up with such a ridiculous hosting paradigm. “But it only costs pennies a month to run!*” Yeah, until she goes viral. This scenario right here is why services like Squarespace et al are still valuable. You’ll pay a few extra bucks a month, but if you go viral, you won’t go bankrupt when the bill is due.
- markhaslam 4y agoWhat are the cold start times like? Compared to say Cloudflare Workers where they claim you can have no cold starts?
- lucacasonato 4y agoDeno Deploy (https://deno.com/deploy https://deno.com/deploy) uses the same optimizations as CFW to achieve effectively 0ms cold starts. Netlify Edge Functions are still in beta and don't have all of the same optimizations yet, but we're going to be working with Netlify over the next few months to enable these optimizations to Netlify Edge Functions too.
- markhaslam 4y agoThank you! That’s so impressive that you are able to achieve 0 ms cold starts in Deno Deploy. That and CFWs are game changers.
- pcj-github 4y agoDoes this complement or compete with Deno Deploy?
- ksajadi 4y agoNetlify for me is a prime example of a great company gone wrong by raising too much VC money. The basic product of Netlify is a great one: build and host static sites without the need to mess with any of the tech stack. For us developer folk, this should be easy: run the build command of any static site generator and stick the results into an S3 bucket. And yet, something as simple as this became so popular with even developer companies (see Hashicorp’s quotes on Netlify). This could have been a great story but then tons and tons of VC money came in and now you’d have to think of ways to make the valuation worth it and make the product sticky: so now we have edge Deno powered functions, lambda-esq applications, form embedded HTML and so much other features that are used by the long tail of their customer base while they changed their price to charge by git committees and have daily short downtimes of 1 to 5 mins for the past month (monitored by external services, as they wouldn’t reflect that in their status page). Soon, they’ll sell the company to some corp like Akamai or similar “enterprise” outfit leaving us high and dry. There is a lot of money in building businesses that do boring stuff that just makes peoples lives easier. But when you take VC money, you’d need to build a moat to fend off cloud providers from the bottom, capture the value for the top from developers and everything in between.
- madeofpalk 4y agoI think this is a natural and fine extension of the Netlify platform. They've had various "serverless functions" for a few years that's mostly been out of the way if you don't need it. It fits within their goal of a 'heroku for frontend websites', for easily deploying sites.
- throwthere 4y agoI guess Netlify still offers the basic static site hosting, which can be anything from drag-drop to easy to set up automated github deployments. I mean, it's not like Netlify offers a worse static hosting service post-funding, right? With VC funding they've just built out more features. Not to mention I think they've always aimed to build out the "JAM" stack and support as many frameworks as possible.
- 3np 4y ago
- slimebart 4y agoHow does this compare to cloudflare workers? CF always seems so cheap compared to alternatives, if you ever expect to scale beyond the developer plans.
- deleted 4y ago[deleted]
- NHQ 4y agoI don't want edge functions, I want edge appliances. An edge function means I still have to run my own janky devops for that specific appliance. Edge IPv6 Appliances or Bust.
- vorticalbox 4y agoWhat advantage does this have over something like https://deno.dev https://deno.dev?
- nojvek 4y agoWe’ve been Netlify paying customers for 2 years now. While I appreciate the new features, the core platform has been becoming unreliable in the past 6 months. We’ve had a decent amount of downtime. I do not recommend them anymore. We will move somewhere else. Almost every few days we get a report that some customers can’t access our site from where they are. Our US east engineers can confirm that their POP is down. Netlify’s status page says everything is working, but in reality it’s not. Netlify as a CDN has failed for us on its core promise.