What is Serverless - Episode 3: Deploying applications globally Written by Edward Hewitt in Engineering on May 01,2019 In Episode 3 from our Serverless series, Sadek and Guillermo discuss how Serverless allows you to deploy applications globally by having smart/application-aware CDNs. This is a transcript of the interview and it will help you to avoid missing out on any of the details, but you should check out the full video and subscribe to our channel to make sure that you see the full series. Highlights: Smart CDNs - Using and enhancing a network of CDNs with functions to be able to serve static and dynamic data Application-aware CDNs provide hight reliability, with no monitoring or observability necessary Placing your functions near your data will cause latency problems Prediction - The future of databases. As for code, databases will be replicable, some kind of multi-master databases Sadek: We're still here at Prismic with Guillermo, and now, I want to talk about another topic of serverless: Deploying globally. Imagine I had a website or an application, I deployed it, and, you know, I have a global success, international. How does serverless adapt to that? If you're using serverless, you can decide to deploy your functions everywhere in the world, so the CDN becomes a lot more smart. Guillermo: So there are two patterns here that I like to think about. A CDN, which is the typical strategy for caching your assets everywhere, works really well with static files and static assets. So when you use our platform, we automatically cache all your static files in every edge of the world, but the question that comes up is, what happens to dynamic data? Not everything can be modelled as a static file. So what happens when you have to render HTML that composes a headless CMS for example, or you have to make queries to a database on-demand as a user comes in. It can return static files immediately, close to where your customer is, it can invoke a function, and then it can cache the result of that function So, if you're using serverless, you can decide to deploy your functions everywhere in the world, so the CDN becomes a lot more smart. It can return static files immediately, close to where your customer is, it can invoke a function, and then it can cache the result of that function which is super interesting, because if you remember from our previous conversation, when you invoke a serverless function you're basically handling an HTTP request. And that means you're responding with HTTP headers, and a body, or maybe an image content, so in the headers you can say Cache-Control, and cache your asset. Sadek: But just before even doing the caching, I like this metaphor about CDN and relating it to a CDN, because even imagine you don't have caching, even if you don't have it. You still can deploy that function and run it, in anywhere around the world. Right? Guillermo: Yes. Absolutely. Sadek: So it's closer to the client anyway, even if you don't have caching. Not only are you getting a scalability benefit, you're getting a reliability benefit, because the analogy that I like to use is, no one ever stresses or gets paged because their image is down at the CDN. Guillermo: Absolutely, and I think that the interesting thing here is, not only are you getting a scalability benefit, you're getting a reliability benefit, because the analogy that I like to use is, no one ever stresses or gets paged because their image is down at the CDN. So there's no mental conception that your CDN could go offline. Or that one of your assets-- Sadek: Because it's a simple model, right? Guillermo: Yeah, it's simple. Sadek: Because it's just a file. You don't have to health check your process or your server to make sure it's up and running, everything loads on demand. Guillermo: It's simple, and the model itself ensures that there's no monitoring or observability necessary. We call this like health checks, you don't have to health check your process or your server to make sure it's up and running, everything loads on demand. So, basically serverless is making the CDN smart, is making it application-aware. Sadek: Right, so basically what happens is that you saved the function somewhere in a global storage, and then you, invoke it on demand, Guillermo: So, it gets a little tricky, Sadek: how does it work? Guillermo: because one of the things that we have to remember is where your source of data is, so if you have your database in the east of the United States, say you have it in Virginia, and then you're trying to execute your function in China, you have to compensate for, you know, there's going to be a lot of round trips. Sadek: Between the... Guillermo: Between China and the US, and if your code runs a lot of logic serially, you may actually be at disadvantage. Sadek: If you separate them away. What I always tell our users and our customers is, you have to think about, placing your functions near your data. And I think there's a new category of application that emerges as a result Guillermo: (laughs) Exactly. So, what I always tell our users and our customers is, you have to think about, placing your functions near your data. And I think there's a new category of application that emerges as a result, which is kind of also in the same vibe of increasing regulation and data ownership and borders around data, is the idea that you can replicate your data, or that data should belong to where the citizens of certain countries are Sadek: Closer to the user. Guillermo: Yes, so you can imagine that a more realistic model for serverless is that China, and I believe they're already doing this, says, you know, I don't wanna be in the same database as every US customer in the East Coast. Sadek: And the new global GDPR, says the same right? (Guillermo laughs) Guillermo: So, your database may actually be in China, and this actually also solves your latency problems, so I think it's-- Sadek: So that's, yeah, I fully agree, and you know, there's something that we try always to solve for people. You know, as a platform, whenever you have data, you need also to make that data available the closest possible to where they are consumed, right? Guillermo: Correct, it's logical right, like, you wouldn't want to transact with a foreign country when you're dealing with your own local problems, so serverless is very natural I think for how databases will evolve. Sadek: So, basically, serverless works the best when the platform that is hosting data is also working in the same kind of model of distributing data closer. Guillermo: Yeah, I would say that what we're seeing today for code, if I had to hazard a prediction, I would say what we're seeing with code is gonna happen very very soon to data. So, we're seeing today that code has been broken down into primitives, like the function, and that functions don't have borders, you can quickly, instantly, deploy them wherever you need or wherever your business is. But databases, we still think of them as servers, with connection pools and limits of connections and so on, not all databases of course and I think, that's why I'm a big fan of when your data can be modelled as a headless CMS for example, I think that's also out of my database problems, but for traditional databases they have to evolve, and we're starting to see this, to make your data more ready for replication. Sadek: And also for moving, because replication is one of the problem, and then people will come up with sharding, and all these techniques, but, Guillermo: Absolutely. Sadek: But they are very kind of not dynamic enough sharding. Guillermo: Yeah, yeah. Sadek: You need to be able to move things around. Guillermo: Exactly, it's almost like you want a customer-level sharding, a pro-level sharding. Sadek: That's what we do actually. And it should be deep in the architecture, exactly, on the server. Guillermo: Yeah. Sadek: Where you have packets of data and you can send them wherever you want them to be. I think it makes total sense, for example, if you have customers in China that have lots of popular deployments for China, why are we replicating all the data of every possible customer in the US, who might never interact with your API endpoint in China. Guillermo: Yeah, because I think it makes total sense, for example, if you have customers in China that have lots of popular deployments for China, why are we replicating all the data of every possible customer in the US, who might never interact with your API endpoint in China. So, I think that we're going towards a very very nice future. Sadek: Some kind of multi-tenant database. Guillermo: Yes, I would say probably multi-master, so that you can not only read from the replica, Sadek: Read and write. Guillermo: but write, in that location. Sadek: Yeah, unfortunately when we had to search for that, there were no technology, we had to write our own, you know, sometimes you regret (Guillermo laughs) writing a database system. Guillermo: Because you wanted that future earlier, yeah. Sadek: Next time, next video, we'll talk more about the developer experience of serverless and how does it impact their experience.
Related posts Unpopular opinion: why required fields lead to terrible UX by Renaud Bressand, on November 05,2018 Development environments: a sandbox where you can test, try, and iterate safely by Edward Hewitt, on June 11,2020