Difficulty: Medium Topics: Marketplace Dynamics, Availability Management, State Machine Key Concepts: Managing TimeSlots, Handling Booking Concurrency.
Phase 1: Requirements Gathering
Goals
Design a platform where Mentees can book sessions with Mentors.
Manage Mentor availability efficiently.
Handle concurrent booking requests for the same slot.
1. Who are the actors?
Mentor: Sets availability, conducts sessions.
Mentee: Searches mentors, books sessions.
System: Manages bookings, notifications, and payments.
2. What are the must-have features? (Core)
Availability Management: Mentors define when they are free.
Booking: Mentees reserve a slot.
Search: Mentees find Mentors by skill/domain.
Notification: Email/SMS confirmation.
3. What are the constraints?
No Overlap: A mentor cannot have two bookings at the same time.
Locking: If two mentees try to book the same slot, only one succeeds.
Phase 2: Use Cases
UC1: Mentor Sets Availability
Actor: Mentor Flow:
Mentor selects Date and Time Range (e.g., "Mon 9-11 AM").
System validates no conflicts with existing bookings.
System saves TimeSlots.
UC2: Mentee Books Session
Actor: Mentee Flow:
Mentee views Mentor's calendar.
Mentee selects an available slot.
System attempts to lock the slot.
If successful, System creates Booking (status: PENDING/CONFIRMED).
System sends confirmation.
Phase 3: Class Diagram
Step 1: Core Entities
MentorshipPlatform: Main controller.
Mentor/Mentee: Users.
Booking: The core transaction.
TimeSlot: Value object for time ranges.
UML Diagram
Phase 4: Design Patterns
1. Observer Pattern
Description: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Why used: When a Booking is confirmed or cancelled, multiple notifications (Email, SMS, Dashboard Update) need to be triggered. Observers allow decoupling the booking logic from the notification logic.
2. State Pattern
Description: Allows an object to alter its behavior when its internal state changes.
Why used: A Booking goes through various states (PENDING, CONFIRMED, COMPLETED, CANCELLED). The State pattern manages the allowed transitions (e.g., you can't cancel a COMPLETED session) and behaviors associated with each state.
Phase 5: Code Key Methods
Java Implementation
Phase 6: Discussion
Concurrency
Q: How to handle 1000 users trying to book the same slot?
A: "Using Java locks only works on one server. For a distributed system, use Database Row Locking (SELECT ... FOR UPDATE on the Slot row) or Redis Distributed Locks (Redlock)."
Calendar Sync
Q: How to sync with Google Calendar?
A: "Two-way sync.
Pull: Webhook from Google notifies our system of new events -> blocked slots in our DB.
Push: When booking created on our platform, use Google Calendar API to insert event."
Search
Q: Optimizing Mentor Search?
A: "Use an Inverted Index (Elasticsearch). Index mentors by Skills, Company, Role. For availability search, store slots as nested objects or range types."
SOLID Principles Checklist
S (Single Responsibility): BookingSystem handles coordination, Mentor handles availability logic.
O (Open/Closed): New Booking Types (e.g., Webinar) could extend Booking.
L (Liskov Substitution): N/A.
I (Interface Segregation): NotificationService could be an interface.
D (Dependency Inversion): Service depends on abstractions (Entities).