Friend Count at Scale for a Bidirectional Relationship Table

System Design · Karat · Easy

Friendships between users are recorded in a relationship table, and a given friendship may be stored with either user in either column. Each of the two user columns has its own index. Propose a design that returns the number of friends a user has and keeps working well at scale. Walk through the trade-offs of the approach you choose.

Loading the rest of the question…