Just a note here that we’ve made an open source version of this in a plugin, which serializes the badges along with the post itself, to address the performance issue mentioned above
As to the selection of which badges will be featured, the user does this themselves in their profile, in a new user-specific setting.