Typically, there are two components in the web - client and server. While clients(actual users) can be located anywhere globally, servers generally are placed basis on where the bulk requests come from. For eg, if you are using AWS services, an Indian company with Indian users will use the Mumbai region to set up their servers, and Singapore company will use the Singapore region. And the same goes for databases, they are typically placed in the same VPC as the VM to provide the best and secure connection between the server and database.
How to decide the server region if your users are global? Choosing any one location will cause long travel and hence large response times. To solve this, you can potentially launch servers in many locations, and divert the traffic using a load balancer to the nearest server. But it comes with its own set of complications -
- You need to manage the deployments and up-time for each all the servers hosted in different geo-locations.
- Database Sync: quite obviously you need to sync the databases across geo-locations, and maintain consistency.
- If you have a cache layer on top of DB(say redis), you need to sync and manage that too.
- Cross geo region requests are expensive. Really expensive.
Obviously, there are better ways to scale up a system with global requests, than running VM behind a load balancer. You can dockerize a service or make it serverless but the overall challenges remain majorly the same.
A content delivery network or content distribution network is a geographically distributed network of proxy servers and their data centers. Or a system of distributed servers(network) all across the globe. All these servers across the globe are called edges or nodes of CDN. These nodes are connected to the central main server. When a request comes, it is returned by the nearest node rather than the main server.
CDN is used for static files(images, js, CSS), nodes of the CDN keeps the copy of these assets from the main server and refreshes them regularly based on expiry. This improves the delivery of static assets up to 6x, and make the website load dramatically fast.
Edge computing is a distributed computing paradigm which brings computation and data storage closer to the location where it is needed, to improve response times and save bandwidth.
What if we can utilize CDN nodes for not just serving static files but also for compute and storing DBs. And that is exactly what compute at edge is.
AWS has something called lambda at edge, Cloudflare has Cloudflare workers and workers KV(key-value) store, designed to achieve the same. Macrometa and few other companies are trying to build a globally distributed data store on the same concept.
This is a game changer. If serverless was big, edge computing is 10x bigger than that. Here are the reasons -
- This allows developers to host their code closer to their users, taking away the network latency problem.
- Being built on top of serverless, scaling is easy with all the advantages of serverless computing.
- No servers to manage, and better load balancing.
- Build better caching systems.
- Offload trivial tasks to edge, like the ACL layer.
These are very top layer use cases, if we deep dive into specific industries the list is infinite. For eg - publishers with a global audience. Since the entire content is static, imagine the amount to time that can be saved in network latency.
My experience so far has been amazing. We are able to run thousands of our creator's websites in PubNinja without allocating any dedicated resources. Fast response times and no fixed costs.