If performance is an issue for you, using a none relational DB, like Mongodb is the way to go.
If you still want to use ActiveRecord, either you use eager loading with Post.comments.include(:user)
(which will load unused users info - and that's not great), or you can use caching techniques.
I find it OK to cache the user.name
in the comments table, as you suggested, as long as you control the changes that can occur. You can do that by setting callbacks in your User
model:
after_save do |user|
Comment.where(user_id: user.id).update_all(:username, user.name)
end
This technique is sort of a DB caching, but, of course, you can cache HTML fragments. And a comment block is a good to cache HTML block.