I spent weeks building my room booking system. Authentication ✅. Authorization ✅.
Business policies ✅. Complex booking rules ✅. I was proud.
Then I got my first code review from my mentor.
The solution my mentor recommended: Pessimistic Locking.
@RepositorypublicinterfaceRoomRepositoryextendsJpaRepository<Room, Long> {
@Lock(LockModeType.PESSIMISTIC_WRITE)@Query("SELECT r FROM Room r WHERE r.id = :roomId")
Optional<Room> findByIdWithLock(@Param("roomId") Long roomId);
}
What this does:
When User A queries the room, the database locks it
User B's query has to wait
User A completes their booking → releases lock
User B's query continues → sees the room is booked
Some lessons come immediately. "Oh, I should validate user input."
This one came late. Through code review. Through a question I couldn't answer.
But now that it's here, I can't unsee it. Every time I write code that touches shared resources, I think: "What if two users do this at the same time?"
That's the sign the lesson stuck.
Day 18 of 90. Learning that foundations matter more than features. 🚀