How to Use Edge Computing to Scale Your eCommerce Business
Tags: edge, ecommerce, computing, tutorial
Published: 2022-12-16 15:49:25

Edge computing isn’t a specific technology, but rather a networking philosophy focused on bringing computation as close to the user and the data source as possible in order to reduce latency and bandwidth use. It means running fewer processes in the cloud and moving those processes to local places, like a user’s computer, an [Internet of Things](https://www.cloudflare.com/learning/ddos/glossary/internet-of-things-iot/) (IoT) device, or an [edge server](https://www.cloudflare.com/learning/cdn/glossary/edge-server/). Bringing computation to the network’s edge minimizes the amount of long-distance communication that has to happen between a client and a server.

Numerous edge-first javascript frameworks like [Vercel](https://vercel.com/), Cloudflare Workers, and many web development platforms are making it easier to adopt edge computing on a large scale. Let’s dive into edge functions, what they are, and why they’re beneficial.

![People smiling around a desk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/54k27m255ye46muaa4zz.png)

## Understanding Edge Functions
Edge Functions allow you to serve content from your CDN server of choice closest to the user. Utilizing Typescript, it’s easy to modify network requests at the edge, so it’s closer to your users. Some of the benefits of edge functions include:

- Provides eCommerce companies with cost-effective, real-time consumer insights
- Enables [personalized content](https://www.peakactivity.com/blog/marketing-personalization) to be delivered with the same high performance as static content
- Mitigates the damage and costs associated with security breaches by filtering out malicious traffic before it reaches a business’s origin infrastructure
- Creates more localized content/present more contextually relevant ads
- Optimizes content by [conducting A/B tests](https://www.peakactivity.com/blog/how-to-measure-the-impact-of-an-a-b-testing-program)
- Reduces latency in delivering content to the user's browser

It’s worth noting that edge functions and serverless functions are not all that different. 

To expand upon this further, serverless functions are small, highly efficient pieces of code that run on broad geographic regions. Imagine the possibility of reducing latency significantly for a California-based user calling that serverless function based on the east coast; this is where edge functions come into play by bringing those serverless functions to their doorstep.

We don’t just ship serverless functions to the edge; we can send entire web applications. Vercel and [Next.js](https://www.peakactivity.com/blog/ecommerce-site-next-js) are leading the charge today. With the release of react server components and the apparent adoption by the community, you can ship server components and static content on the edge, delivering unparalleled experiences.

For more on the subject, I recommend reading Salma Alam-Naylor’s [article](https://www.netlify.com/blog/edge-functions-explained/), _Understanding Edge Functions: The Edge and Beyond_.

![Engineers at their desk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/977lkyc71exmv0hsqiu5.png)

## A Double-Edged Sword
While edge functions may seem to pose nothing but upside, it’s not uncommon to face some implementation challenges, including: 

**Unified Manageability Across Edges**

This can be difficult and is becoming increasingly more accessible with the help of companies like Vercel and AWS.

**Security and Privacy**

Zero trust security architecture is one of the latest paradigms that believe that no aspect of data communication is secure. Implementing something like this with real-time low latency requirements continues to prove to be a major challenge.

**Artificial Intelligence (AI) & Machine Learning (ML) Models for Edge**

AI & ML can be a challenge because to derive the value of the data generated across the various edges, vast data points associated with a single end-user or a single device must be processed and analyzed at a constant time interval.  

## PeakActivity and the Cutting Edge
Now that we discussed what edge functions are, let's talk about how PeakActivity is utilizing this functionality in a highly sustainable and impactful way.

We recently engaged with a client to help bring speed, stability, and scalability to their users. After spending a few weeks learning about their current architecture and factoring in the upcoming holiday season, we decided to bring speed incrementally through edge computing.

At the time, Vercel was not ready for edge functions, and the client was already on AWS, so we decided to utilize the [Lambda@Edge](https://aws.amazon.com/lambda/edge/) feature. Since the functionality was based on Node + Typescript, we could easily chunk the existing extensive API into smaller, more composable serverless functions. Right out of the gate, we yielded one colossal benefit: cost savings. We went from a high availability EKS cluster to a dozen smaller lambda functions which you only pay for what you use. We deployed these on edge now that we have a dozen lambda functions. 

The total time spent implementing these changes was approximately 30 days end-to-end. We abstracted the extensive REST API to smaller serverless functions, reused it where necessary, and deployed it on edge. All of this within 30 days provides tremendous incremental value.

Now that Vercel supports edge functions, we can better adapt this functionality. Vercel now provides an edge middleware to convert or create new server APIs directly from the Next.js application. 

![Edge Function Diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xapmzm2jjbqskhgiigof.png)

Now that we discussed what edge functions are, let's talk about how PeakActivity is utilizing this functionality in a highly sustainable and impactful way.

We recently engaged with a client to help bring speed, stability, and scalability to their users. After spending a few weeks learning about their current architecture and factoring in the upcoming holiday season, we decided to bring speed incrementally through edge computing.

At the time, Vercel was not ready for edge functions, and the client was already on AWS, so we decided to utilize the Lambda@Edge feature. Since the functionality was based on Node + Typescript, we could easily chunk the existing extensive API into smaller, more composable serverless functions. Right out of the gate, we yielded one colossal benefit: cost savings. We went from a high availability EKS cluster to a dozen smaller lambda functions which you only pay for what you use. We deployed these on edge now that we have a dozen lambda functions. 

The total time spent implementing these changes was approximately 30 days end-to-end. We abstracted the extensive REST API to smaller serverless functions, reused it where necessary, and deployed it on edge. All of this within 30 days provides tremendous incremental value.

Now that Vercel supports edge functions, we can better adapt this functionality. Vercel now provides an edge middleware to convert or create new server APIs directly from the Next.js application. 

![Elderly couple smiling at their computer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kbitrawfsdg6wfzak8uh.png)

## The Edge of a Better Experience
Like so many advancements in technology, the person who benefits the most from edge computing is the end user, and rightly so. Edge computing allows companies to provide their customers with an improved user experience and that—at the end of the day—is what drives eCommerce. Businesses that fail to continually optimize their user experiences by leveraging new technologies or processes like edge computing are not only letting their customers down but do so at their own risk.