Cordial 如何利用 Cloudflare Workers 处理黑色星期五的流量激增

Black Friday is the biggest day of the year for retailers. But what if your customers are the retailers?

从用户获取到促销、个性化的废弃购物车营销活动以及交易发货确认,电子商务世界是由规模巨大的 1:1 通信渠道推动运行的。

One company that powers the customer engagement programs for some of the world’s leading brands is Cordial, a marketing automation platform built from the ground-up to deliver highly personalized messages via any content channel — including email, SMS, in-app notifications, and more. Unlike most marketing tools, Cordial empowers developers to customize the product to suit their needs, while maintaining an intuitive front-end that enables marketers to execute sophisticated, impactful orchestrations without the need for technical resources.

The Cloudflare Difference

在 2018 年初,Cordial 改用 Cloudflare 作为其网络提供商。Cordial 的平台架构师 Daniel Smith 说,他们见证了可立刻获取的重大改进,并解释说:“无需进行额外开发,我们就立即获得了巨大的收益。”

将 Cordial 迁移至 Cloudflare 的网络后,发送到 Cordial 服务器的 80% 的请求被骤然路由到 Cloudflare,从而节省了大量带宽并大大改善了性能。更棒的是,通过启用 Cloudflare 的 Argo Smart Routing,Cordial 发现其 API 服务器延迟下降,平均响应时间从启用 Argo 前的 650 毫秒下降到 403 毫秒,第一天就降低了超过 35%。

cordial image 1 argo enabled uncacheable

Uncacheable API Request Latency (lower is better)

cordial image 2 argo static

Static Content Latency (lower is better)


Cordial 不是一家零售公司,但其客户却是。黑色星期五是一年一度的促销大奋战活动,要么全力以赴,要么坐以待毙。在线购物者缺乏耐心,网络性能不佳或链接断开足以让其转而选择竞争对手的产品。Cordial 需要站在游戏的顶端:它必须像零售商一样思考,在黑色星期五到来前几周预测和管理大量的流量,并在当天应对汹涌而至的巨大流量。

Cloudflare’s Content Delivery Network and Argo Smart Routing helped put Cordial on solid footing. But for the main event, Cordial turned to a powerful new tool: Cloudflare Workers.

Workers at the Ready

Cloudflare Workers 的核心是一个革命性的概念:使用 Cloudflare 全球云网络中的服务器(即距每个访问者最近的计算机)来执行沙箱代码,而无需专用的虚拟机或容器。通过缩短浏览器与处理请求的计算机之间的距离,Cloudflare Workers 可以从根本上减少延迟,从而以较低的成本获得巨大的性能提升。

在黑色星期五的前期准备中,Cordial 构建了数十个微型应用程序,平台架构师 Daniel Smith 称其为“一系列 Workers”,公司随时准备进行部署。各 Worker 适合处理特定的工作,例如减少疑似垃圾流量,或在关键时刻将某些类型的请求路由到特定的服务器以减少负载。团队还起草了相应的“活动日”文档,概述了哪些突发事件应调用哪个 Worker。

最终,当黑色星期五周末活动席卷互联网时,Cordial 做好了准备。它通过一系列 Workers,发送了数百万封电子邮件、短信和其他信件,没发生任何故障。

Looking Ahead

Cordial has also found additional innovative ways to put Cloudflare Workers to use. When one of its customers requested a feature — a way to generate and embed custom barcodes in customers’ emails — Cordial used Workers to develop a bespoke app. Using Rust, compiled to web assembly, Cordial’s Workers app generates and delivers a barcode image on-the-fly in Workers without needing to spin up any additional servers (try this link to see it in action). Better yet, Smith says that since deploying the app, the team rarely has to think about it.

“If it weren’t for Cloudflare Workers, we’d be managing another cluster of servers to run this microservice, which means additional maintenance costs and overhead. With Workers, we don’t have to worry about it.” — Daniel Smith, Cordial Platform Architect


A Barcode Generated On-the-Fly by Cordial's Workers App

Cordial 如何利用 Cloudflare Workers 处理黑色星期五的流量激增

    •现在 80% 的请求都被路由到 Cloudflare 服务器,从而节省了大量资金并提高了性能

    •使用 Argo Smart Routing,第一天就将 API 服务器延迟降低了 35% 以上

    •建立一系列自定义 Cloudflare Workers,以实时管理流量需求

    若没有 Cloudflare Workers,我们将需要管理另一个服务器集群来运行此微服务,这意味着额外的维护成本和开销。有了 Workers,我们不必担心了。

    Daniel Smith
    Cordial 平台架构师