Which languages does Facebook and YouTube used to sort posts based on user activities?
Darcy Dar'c Youtube is written Python, C, C++, Java and recently some features with Go language for its backend functioning And facebook is manily framed in php and it's framework and recently some of their feature is created with python and nodejs As far is about sorting things for that it might looks like they followed "Market basket analysis" algorithm and record every user activity and show them content which they views on regular bases. As far as about "market basket analysis" as when we go in market and buy some things like bread then near bread rack their is rack of butter and this is complement by the "suggestion systems" or "Recommendation System" which are worked on suggesting things which we buy and give us some suggestions what else we can buy which complement and other user buy Similarly YouTube and facebook assist the pattern which you are viewing and showing you things according to that recognize pattern else other sorting with option has own algo https://www.shopify.in/blog/youtube-algorithm
sorting messages is handled by a sorting algorithm, not a specific language. most likely this is some kind of backend language (probably even a framework)