Concatenation Is Not Merging

A hybrid feed pushes ordinary posts into a materialized timeline and pulls posts from accounts above the celebrity threshold at read time. Users report that celebrity posts almost never appear in their feed, even minutes after publication, and the fan-out and pull services both look healthy.

def home_timeline(user_id, limit=50):
    pushed = timeline_cache.range(user_id, 0, limit)   # newest first, up to `limit`
    pulled = []
    for author in celebrity_follows(user_id):
        pulled.extend(posts_by_author(author, limit))  # newest first, per author

    merged, seen, out = pushed + pulled, set(), []
    for p in merged:
        if p.id in seen:
            continue
        seen.add(p.id)
        out.append(p)
    return out[:limit]

What is wrong?

A

timeline_cache.range(user_id, 0, limit) uses an inclusive upper bound, so it returns limit + 1 entries and pushes the pulled posts past the truncation point by one

B

merged is a concatenation, not a merge: every pushed post precedes every pulled post, and pushed already holds limit entries for any active user, so the truncation at the end discards the celebrity posts before they can be ranked

C

seen is keyed on p.id, so a celebrity post that was also pushed to some followers is treated as a duplicate and removed from the pulled list

D

posts_by_author is called once per followed celebrity, so the read fans out into many queries and the tail latency exceeds the client timeout before the merge runs