Abstract: We present a model of social media where users are connected in a network determined by social ties, but also receive recommendations from external content sources chosen by the platform. Users dynamically update their beliefs and preferences for content based on what they observe, which determines their engagement with the platform over time. Using a projected gradient descent (PGD) algorithm, we fully characterize the optimal recommendation algorithm for an engagement-maximizing platform as a function of the social network, the time horizon, and the distribution of available content. Our tractable analysis leads to three main insights. First, we show that homophilic social networks are exacerbated by social media algorithms and can drive users to become even more polarized. Second, we demonstrate that forward-looking platforms may have incentives to manipulate existing users’ beliefs to promote higher future engagement (e.g., sending them down “rabbit holes”). Finally, we show that platform algorithms become particularly pernicious when extreme sources become available, allowing the platform to more easily tailor content to each user’s preferences.