🎓 A1Learner
🔍
0 of 47 lessons completed

Push and Pull CDNs

Push and pull are the two ways a CDN fills its edges with files. Push sends each file to every edge before anyone asks, and pull lets an edge fetch a file on its first request.

Push sends at publish time

One file is published to 2 edges. Both sends happen before any request arrives.

sends = 0
edges = {"edge A": set(), "edge B": set()}

for name in edges:
    edges[name].add("poster.jpg")
    sends += 1
    print("at publish, sent to", name)

print("total sends:", sends)
for name in edges:
    print(name, "answers from its copy, sends stay", sends)

Pull sends on first request

Publishing sends nothing here. Each edge fetches the file when its first request arrives, and only then.

sends = 0
edges = {"edge A": set(), "edge B": set()}
print("at publish, sends:", sends)

for name in ["edge A", "edge A", "edge B", "edge B"]:
    if "poster.jpg" not in edges[name]:
        edges[name].add("poster.jpg")
        sends += 1
        print("first request at", name, "caused a send")
    else:
        print(name, "answers from its copy")

print("total sends:", sends)

A file nobody requests

This file is published and then never asked for. The two strategies pay very different sending costs.

edges = ["edge A", "edge B"]

push_sends = len(edges)
pull_sends = 0

print("push sends:", push_sends)
print("pull sends:", pull_sends)

Example

files = ["a.jpg", "b.jpg", "c.jpg"]
edges = ["edge A", "edge B"]

push_sends = 0
for name in files:
    for edge in edges:
        push_sends += 1
print("push sends at publish:", push_sends)

at_edge = {"edge A": set(), "edge B": set()}
pull_sends = 0
for name, edge in [("a.jpg", "edge A"), ("b.jpg", "edge A"),
                   ("a.jpg", "edge A"), ("b.jpg", "edge A")]:
    if name not in at_edge[edge]:
        at_edge[edge].add(name)
        pull_sends += 1
print("pull sends after those requests:", pull_sends)

Key points

  • CDN push: the origin sends each new file to all edges at publish time.
  • CDN pull: an edge fetches a file from the origin the first time a user asks that edge for it.
  • Use push when every edge should hold a file from the moment it appears.
  • Use pull when only some edges will ever be asked for a file.

In this example, 3 files are published to 2 edges. Push sends 6 copies at publish time, while pull sends only 2, because the requests touch 2 file and edge pairs.

Note

push pays the sending cost even for edges nobody asks, while pull makes the first request at each edge wait.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

A file appears, and each edge fetches it only when a user first asks that edge for it. Which method is this?