Skip to content
Keshav Raj
Identical exam question cards served from a CDN edge node to many different learners.
ARCHITECT HILLSLEARNER-FREE
SHIPPED Learner-independent responses with version-key invalidation at the CDN.I OWNED Co-designerOUTCOME LEARNER-FREE

CDN-cached mock-test questions

Keshav RajCo-designer · 2022 · ShippedContact meResume PDF

Context

In 2022 I co-designed how mock-test questions are delivered through a CDN, and implemented the read path on both client and server. A teammate did the asynchronous evaluation half.

The problem

A mock test starts for many learners at once. Every learner pulled the full question set from the origin, and submit was evaluated synchronously. A per-learner, authenticated response cannot be cached at a CDN as it is.

What I did

  1. I created new learner quiz APIs on the backend and served questions through the CDN. The CDN does not forward the standard Authorization header, so I added a custom header on client and server.

  2. I made the questions response learner-independent: I removed the per-attempt ID from the request and keyed the cache on the quiz's last-updated timestamp.

  3. Randomized papers come from server-side sets, so they stay cacheable.

  4. I added invalidation: a worker and question hooks bump the quiz timestamp whenever questions change.

Key decision

I cached the read path at the CDN with version-key invalidation. Evaluation became asynchronous, which was the team's half.

The trade-off was a custom auth header and a cache key that must be bumped on every question edit. If that bump is missed, learners see old questions, so I put it in hooks and a worker rather than rely on people.

Result

Question responses are now learner-free and cacheable at the CDN.

What I learned

I would do version-key invalidation again. I would add a metric on cache hit rate at launch, so the gain could be shown.

Stack

  • Ruby on Rails
  • CloudFront
  • React Native
  • Next.js
Play the world →