CDN Know-how: Run JavaScript on CDN Edge Nodes with EdgeRoutine

Cloud-native and Edge Computing Are the New Normal

Cloud-native Services Are Growing Fast

Cloud-native has become a worldwide technology trend in recent years as enterprises are accelerating their cloud migration efforts. The implementation of cloud-native technologies has tremendous momentum in both public and private clouds and is expected to enter a phase of “explosive growth” according to analyst firms like Gartner.

5G is Bringing Edge Computing to Front and Center

Edge computing is another emerging sector continuously gaining popularity. As an integral part of this technology, CDNs are the most effective facilitators since they are able to run computing services on their globally-deployed edge nodes. The most important benefit of edge computing is its ability to improve network performance by reducing latency. Gartner even predicts that by 2025, the promise of such low latency will attract three-quarters of enterprise-generated data to be created and processed at the edge. Currently, edge computing is permeating every aspect of our daily lives such as transportation, healthcare, and entertainment.

Innovations Through the Combination of Cloud-native and Edge Computing

With traditional infrastructure as a service (IaaS), services are delivered using abstracted physical servers, such as Elastic Compute Service (ECS) instances, Elastic Container Instances (ECIs), or even higher-level architectures like serverless or FaaS. As the service boundary keeps moving up, isolation costs are falling. Therefore, now cloud customers enjoy better-performing auto scaling and flexible pay-as-you-go billing plans. Alibaba Cloud CDN has deployed more than 2,800 edge nodes worldwide. We draw upon the design thinking behind the two most popular technologies — cloud-native and edge computing — while also combining their applications. Currently, we are exploring the innovative technologies and products that could result from applying serverless computing at the edge.

What Is EdgeRoutine?

EdgeRoutine is an edge serverless computing environment developed by the Alibaba Cloud CDN team. EdgeRoutine makes it easy for users to run custom JavaScript or WebAssembly (not currently available) code on CDN edge nodes. This means you do not have to worry about hardware configurations, deployment regions, scheduling, or elastic scaling. After the code is deployed to the production environment, the system automatically runs and executes the code on all edge nodes globally. EdgeRoutine has the following four characteristics:

  • EdgeRoutine allows a maximum upload size of 1 MB for individual files and supports uploading webpack bundles (bundle.js files).
  • EdgeRoutine supports the triggering of multiple types of events, such as fetch, chrome, and set.
  • Deployment across the extensive network of edge nodes facilitates nearby access by end-users.
  • After code checks are complete, changes take effect within seconds, and the modified configuration is refreshed within seconds.
  • Dynamic Content Delivery Network (DCDN) accelerates origin pulls.
  • Given that EdgeRoutine is a lightweight serverless computing platform whose performance relies on the efficient use of network bandwidth, certain limits are applied to files, processes, and socket speed. It only supports HTTP and HTTPS traffic.
  • We do not recommend storing sensitive data in EdgeRoutine. Features like edge key-value store and data caching will be added later to facilitate computing and data storage.
  • It supports the standard Service Worker Web API, allowing front-end applications to adapt to the web application without any changes.
  • Through integration with the CDN, EdgeRoutine allows extending services with custom CDN logic and implementing a highly programmable CDN for specific requirements.

Technical Principles of EdgeRoutine

CDNs have a multi-level cache hierarchy that reduces latency for static content delivery by pulling and caching static assets from the origin to the CDN node closest to the client. The static content can be fetched directly from the cache instead of origin servers upon requests, which shortens the distance the data must travel and speeds up content delivery. Alibaba Cloud CDN offers a multi-level (two levels by default) cache hierarchy that significantly improves the cache hit ratio and cuts down on origin requests.

Use Cases

  • CDN-related Functions: Use EdgeRoutine to execute custom code for functions like request interception, traffic throttling, content generation, multi-source data merging, and asynchronous authentication. These CDN functions are highly programmable and support the flexible modification, testing, and canary release of code provided by EdgeRoutine. EdgeRoutine enables enterprises of all sizes to combine and implement functions independently and promptly with no need for additional operations.
  • Front-end Service: EdgeRoutine supports features such as web API deployment, web acceleration, HTML parsing, Edge Side Includes (ESI), and edge server-side rendering (SSR). You can also implement edge-optimized API gateways to shift traffic. Browser rendering optimizations can’t be overemphasized in the application of ever-changing front-end technologies. Therefore, CDNs are developed to cater to this need through their accelerated delivery of static content, such as CSS, JavaScript, images, and videos. In addition, EdgeRoutine is blazing a trail for front-end performance optimization with its introduction of edge computing in collaboration with cloud computing and clients. This allows offloading the computational stress on web browsers/app clients to edge servers, where certain front-end and non-intensive computing tasks are performed. It is fair to say that EdgeRoutine is contributing to the further development of micro-frontend architecture.
  • Canary Release: Developers perform A/B tests to compare code and app versions as a way to implement canary release. Not only does this improve performance stability, but it also allows users to systematically optimize and quickly roll back updates, providing a clearer breakdown of conversion rates and user acquisition rates for new features. For example, developers can partition geographical regions for canary releases at a finer granularity, such as at the region or province level.
  • IoT Data Convergence and Computation Offloading: IoT devices use a gateway to analyze generated data and store analysis results in a data center system. This process involves data aggregation, analysis, and transmission to the central hub. Edge computing helps collect and combine pre-aggregated data and then distributes large-scale offline or stream computation to edge nodes, reducing latency and alleviating computational stress on clients and the origin server.

Typical Applications

This section demonstrates some of the typical applications of EdgeRoutine.

1) Speed Up Websites

We’ve all had the annoying experience of visiting websites on 3G and 2G connections. Having a faster 4G connection has helped with the situation, and 5G will offer even higher speeds.

2) Take the Load Off Origin Servers with Edge Computing

Computation occurs whenever we use mobile apps and desktop clients. The dynamic logic computing must be processed by virtual servers on the cloud. Even the simple operation of entering an account password requires data authentication by an origin server. These tasks generate high latency and a large number of queries per second (QPS), putting a great deal of stress on the origin servers.

3) Edge Serverless

Faced with the hundreds of millions of connected smartphone devices, developers of popular apps generally need to evaluate client-side performance, use canary updates for multiple app versions, and A/B test new features to monitor performance and conversion rates. However, using the origin server alone to handle the requests from such a massive number of clients would undoubtedly generate an excessive QPS and crash the origin servers. Therefore, in most cases, only 3% or 5% of the total clients would be chosen as test samples.

Tutorials and Demonstrations

We’ve built a command-line utility, edgeroutine-cli, that works on macOS, Windows, and Linux. It offers support for the debugging, uploading, canary testing, and canary release of code. Learn more about edgeroutine-cli at using the following links:

Demonstrations

1) EdgeRoutine Demo: Hello World

Original Source:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store