DEV Community

swyx
swyx

Posted on

What Happens When A User Edits A Post on Dev.to?

I am catching up on Ben's posts on web perf and I still don't quite get what happens when a post is edited. I understand that things are cached but doesn't that mean that if a post is edited it will take an unpredictable amount of time to update to CDNs all around the world? What are the best practices around this? Does it cost anything to do this? These are the kinds of questions I have when wondering about what I would run into if I were to make a dev.to clone.

Top comments (8)

Collapse
 
ben profile image
Ben Halpern

doesn't that mean that if a post is edited it will take an unpredictable amount of time to update to CDNs all around the world?

Yes, but once it hits the CDN, everybody gets the new copy. It's a matter of knowing that there will be a high read-to-write ratio to justify the strategy. Any post will get many orders of magnitudes of reads for every write. Under some circumstances we also make use of "stale while revalidate" where users see the stale version until they see a fresh version. We don't do this on article pages where we owe it to the author to not show stale, but in some places it's perfectly fine.

But on top of that, requests that hit the origin aren't that slow.

Collapse
 
kspeakman profile image
Kasey Speakman

I am hardly ever happy with my posts no matter how many times I read them, so I edit a lot. I frequently see cached copies of my posts. Even after I Ctrl-F5 to see the updated copy. When I go back to it thru notifications, I'll get the original copy again. (Mainly applies to comments, I think.) I always wondered which version others were seeing, but I assume it was the very first one.

I also notice that sometimes I see an edit link on my comments, and sometimes not.

Collapse
 
isaacdlyman profile image
Isaac Lyman • Edited

I also see this a lot. In fact, just today I was thinking I should send in a bug report to Ben and the team. Thanks for calling this one out.

Thread Thread
 
ben profile image
Ben Halpern

Thanks a lot. This was a case where I'm not surprised it happens but grossly misread the frequency. Knowing this will definitely help us prioritize this. A bug report detailing where exactly it happens would still be appreciated.

Thread Thread
 
isaacdlyman profile image
Isaac Lyman

It happens pretty reliably like this:

  • write a post or comment and publish it.
  • edit it and publish.
  • someone else likes your post.
  • go to the Notifications screen.
  • click the post that was liked.
  • after a long delay, the original (unedited) post is displayed.
Collapse
 
ben profile image
Ben Halpern

Thanks for the heads up. I think there are some cases we are not properly handling. We'll get it worked out.

I also notice that sometimes I see an edit link on my comments, and sometimes not.

Yeah that's a known bug we're working on.

Thanks for feedback Kasey.

Thread Thread
 
kspeakman profile image
Kasey Speakman

No worries man. Y'all do a great job. And after all:

There are only two hard things in Computer Science: cache invalidation and naming things.

-- Phil Karlton

Collapse
 
swyx profile image
swyx

thanks Ben! There are tradeoffs to make for sure. I think part of my hesitation is analysis paralysis. Having someone like you be transparent as to how you do things really helps (in case I need to do this in future)! thank you!