I'm designing a system that like the majority of social related application has posts, people can like the posts and comment on them.And also like the majority of the applications the users can see how many like/comments a post got.The problem is that to show these numbers I would have to count all the likes and comments every time a post is loaded or keep counters in the posts.I think that counting the likes and comments every time will be bad performance wise so I decided to go with the second solution. But because the posts now have to store the counters, every time someone likes a post the version will have to be updated.I'm worried that since multiple people can interact with a post at once the occurence of OptimisticLockingExcpetions can be high and it will annoy my users.What do you guys think?
Problem related to optimistic locking performance
java;performance;orm;locks;jpa