Published 4 min.

How to go viral on X (ex-Twitter, from the actual source code)

How to go viral on X (ex-Twitter, from the actual source code) cover image

X open-sourced their recommendation algorithm. I read it. Here’s exactly what makes posts go viral.

After diving deep into the actual source code, I found the exact signals that determine whether your tweet gets 100 views or 100,000. No guesswork. No “growth hacker” theories. Just what the code actually says.

Here’s everything you need to know.

Executive summary

Basically everything comes down to 7 signals that control your reach:

  • Avoid engagement bait
  • Get verified
  • Ask questions to drive replies
  • Write content worth pausing for
  • Reply to every comment on your posts
  • Post when audience is active

So do this:

  1. Avoid reports, mutes, and spam patterns
  2. Your followers’ engagement amplifies your reach
  3. Get verified to reach non-followers
  4. Replies > retweets > likes
  5. Make people stop scrolling to read
  6. Reply to comments on your own posts
  7. Get likes and replies in the first 30 minutes

How the algorithm works

The algorithm predicts: will this user engage with this post? Each post gets scored by the Heavy Ranker using:

plain text
Score = Σ (Weight × Predicted Engagement Probability)

Predicted Engagement Probability is a machine learning prediction (0 to 1) of how likely YOU are to perform a specific action on a post:

  • Probability you’ll like it
  • Probability you’ll reply
  • Probability you’ll retweet
  • Probability you’ll watch the video
  • Probability you’ll click and engage

Each prediction is made by a neural network trained on billions of past interactions.

Weight is how much X values each action. These are tunable parameters (range: -10,000 to +10,000) that X engineers can adjust in real-time without deploying code:

  • Higher weight = that action matters more for ranking
  • Negative weight = penalizes content (e.g., reports = -20,000)
  • Zero weight = action is ignored

The 7 ranking signals

1. Engagement velocity

The algorithm tracks engagement in 30-minute windows. A post with 50 likes in 10 minutes beats one with 500 likes over 2 days.

Post when your audience is online. The first hour is critical.

2. Author replies

When you reply to comments on your own post, the entire post gets boosted. This is tracked as reply_engaged_by_author.

Reply to comments. Don’t just like them, also respond.

3. Dwell time

How long users stop scrolling to read your post. Tracked as PredictedDwellScoreFeature.

Write longer posts. Use line breaks. Create content worth pausing for.

4. Engagement weighting

Not all engagement is equal:

TypeWeight
RepliesVery high
RetweetsHigh
BookmarksMedium-high
LikesMedium
Link clicksLow
Ask questions. Make statements people want to respond to.

5. Verification

Verified accounts bypass the SocialContextFilter this filter restricts whose content appears to non-followers.

Get verified. It’s not just a badge, it unlocks distribution.

6. Network amplification

When someone you follow engages with a post, it gets boosted in your feed. Relationship strength matters.

Build genuine connections. Engage consistently with your niche.

7. Video metrics

For videos 10+ seconds, the algorithm tracks:

  • 50% retention threshold
  • Total watch time
  • Full-screen viewing
Hook viewers in 2 seconds. Structure content to retain past 50%.

What kills your reach

Negative feedback

  • “Not interested” clicks
  • Mutes and blocks
  • Reports (can weight up to 20,000)

Quality flags

  • Spam patterns
  • Engagement bait
  • Low-quality content

Safety violations

  • Toxicity
  • NSFW content
  • Violence

The viral post formula

  1. Hook immediately
  2. Deliver value (dwell time)
  3. Invite response (replies)
  4. Reply to comments (author boost)
  5. Post at peak hours (velocity)
  6. Be verified (distribution)
  7. No spam signals

What doesn’t work

  • Follow/unfollow schemes are going to be detected
  • Engagement pods will be flagged
  • There is no evidence that hashtag stuffing helps
  • Buying followers will not improve predictions

The algorithm optimizes for genuine engagement. Gaming doesn’t work.

Bottom line

X’s algorithm predicts engagement and ranks accordingly. Create content that genuinely engages people, reply to your comments, and avoid spam triggers.

SignalAction
VelocityPost when audience is active
Author repliesReply to your own comments
Dwell timeWrite substantive content
RepliesAsk questions
Video10+ seconds, aim for 50% retention
VerificationGet verified
NetworkEngage with your niche
AvoidSpam, engagement bait, reportable content

That’s what the code says.


Source: X’s open-sourced recommendation algorithm.