Companies like linked-in always think about how they can make something scale because they take massive future growth into account.
There are various ways to make sorting work in the general case but it always involves chopping up the data into pieces.
- External sort: if sort data doesn't fit into memory (Size M), spool it off to disk (N blocks of size M), read N blocks back in, see which row is the lowest (or highest), pass it on as a sorted stream.
- Parallel sort: same as the external sort but done on a group of servers, each potentially doing an external sort but hopefully not. (fairly good scaling)
- Time-based : Take all the rows that are coming from a service (say log file) in any given time-frame (ex 1 hour), sort those and pass them along (incomplete sorting)
- Group based: like time-based it only looks at groups of the data, for example all records/rows belonging to a certain customer. (if you know that the streamed rows are grouped together)
Also, for specific cases you could indeed easily determine a top 10 of records, keep them in-memory.