On paper a tutor marketplace is a solved problem. You have supply, you have demand, you have a calendar, you have Stripe. Two weeks of work.

The actual complexity turned out to sit in three places I underestimated badly: availability modelling, booking concurrency, and the fact that money and trust are entangled in a way that a normal e-commerce checkout never has to deal with.

Here is what bit me, with the parts that eventually worked.

1. Availability is not a calendar

My first model was the obvious one. A tutor_availability table with start_time and end_time rows. Tutor says they are free Tuesdays 4pm to 8pm, you insert a row.

This falls apart immediately for three reasons.

Recurrence. "Tuesdays 4 to 8" is a rule, not a row. If you materialise it into concrete slots, how far forward do you generate? Six months of slots for ten thousand tutors is a lot of rows that mostly never get booked. If you do not materialise it, every search query has to expand recurrence rules at query time, which is slow and awkward to index.

Exceptions. The tutor is away next Tuesday. Now you have a rule plus an override, and your query needs to apply both. Then they move the Tuesday slot permanently from next month, so you have a rule with an end date and a second rule with a start date.

Time zones. This is the one that cost me the most. A tutor in London offering 4pm slots to a student in Mumbai is not offering a fixed UTC time, because when DST shifts in one region and not the other, the relative gap changes. If you store availability in UTC you get silently wrong slots twice a year. If you store it in local time with a zone, every query needs conversion.

What I settled on was storing the rule in the tutor's local time with an explicit IANA zone, plus a materialised slot table covering a rolling window ahead, regenerated by a job when rules change.

sql
create table availability_rule (
id uuid primary key,
tutor_id uuid not null references tutor(id),
weekday smallint not null, -- 0..6 in tutor local time
start_local time not null,
end_local time not null,
tz text not null, -- 'Europe/London'
valid_from date not null,
valid_until date
);

The rolling window is a compromise and I am still not fully happy with it, but it makes search queries straightforward and keeps row counts manageable.

2. Two students booking the same slot

This is where I learned that application-level checks are not enough.

My first implementation did the obvious thing: query for conflicts, and if none, insert the booking. Under any real concurrency this double-books, because two requests can both pass the check before either inserts. Classic read-then-write race.

I tried a transaction with SELECT ... FOR UPDATE on the slot row, which works but only if slots are materialised rows you can lock, and it serialises more than I wanted.

What actually solved it cleanly was pushing the constraint into Postgres with an exclusion constraint over a time range:

sql
create extension if not exists btree_gist;

create table booking (
id uuid primary key,
tutor_id uuid not null references tutor(id),
student_id uuid not null references student(id),
period tstzrange not null,
status text not null,
constraint no_overlap_per_tutor
exclude using gist (
tutor_id with =,
period with &&
) where (status in ('pending', 'confirmed'))
);

Now the database refuses overlapping bookings for the same tutor, and the application just handles the constraint violation as a normal "slot taken" response. The where clause matters: cancelled bookings should not block the slot forever.

The thing I would tell anyone starting this: put the invariant in the database. Every booking system eventually grows a second code path (admin panel, bulk import, a background job) and the application check will not be in that path.

3. Money arrives before the service does

This is the part that makes a marketplace different from a shop.

When a student books, they pay. But the tutor has not done anything yet, and will not for another four days. So the platform is holding money against a future obligation, and every edge case around that obligation needs a decision encoded somewhere.

The student cancels 48 hours ahead. Full refund, probably. Two hours ahead? Partial, maybe none. The tutor cancels. Full refund plus something for the inconvenience. Neither party shows up. Now you are adjudicating.

The session happens and the student says it was useless. This one has no clean answer and whatever you decide becomes policy.

I ended up modelling the booking as an explicit state machine rather than a boolean is_completed, because every transition has a payment consequence:

pending -> confirmed -> in_progress -> completed -> paid_out
| | |
+-> expired +-> cancelled_by_student +-> disputed
+-> cancelled_by_tutor
+-> no_show_student
+-> no_show_tutor

Each transition carries a payment action: hold, release, partial refund, full refund, payout. Writing it as a table of (from_state, to_state, actor, payment_action) rather than as scattered conditionals was the single biggest improvement to my sanity.

Payouts bring their own problems. Tutors are individuals in many countries, which means onboarding, tax information, and payout schedules that differ by region. I used a payments provider's connected account model rather than touching any of this directly, and I recommend that strongly. Holding other people's money is not a feature worth building.

4. Verification has a lifecycle, not a checkbox

I initially stored is_verified boolean. That is wrong in a way that matters.

Background checks and certifications expire. A tutor verified in March may not be verified in September, and the platform's whole proposition to a parent rests on that status being current. So verification needs an issue date, an expiry, a type, and a jurisdiction, and the expiry has to actually gate something.

The important design point: expiry should remove the tutor from search results automatically, not generate a report for somebody to read. I had it as a report first. Reports do not get read.

sql
create table tutor_credential (
tutor_id uuid not null references tutor(id),
kind text not null, -- 'identity', 'background_check', 'qualification'
jurisdiction text,
issued_on date not null,
expires_on date,
verified_at timestamptz
);

Search then joins against a view of tutors whose required credentials are all currently valid. One query, no human in the loop.

5. Search is a multi-dimensional filter problem

The query a parent actually runs is: chemistry, secondary level, available Tuesday or Thursday evening in my timezone, under a price ceiling, verified, rated above some threshold.

That is five or six filters, one of which is a time range in a different timezone from the stored data, and it needs to return in under a second. Doing this with joins across availability, credentials, subjects and pricing got slow fast.

What helped was precomputing a denormalised search table, refreshed on change, with availability flattened into coarse buckets (weekday plus morning, afternoon, evening in UTC) for the initial filter, then exact slot checking only on the shortlist. Two-stage filtering rather than one perfect query.

What I would do differently

Model availability as rules from day one, not as rows. Converting later was painful.

Put booking invariants in the database immediately. The exclusion constraint should have been the first migration.

Write the state machine before writing any booking code. Every conditional I avoided by doing this would have become a bug.

And decide the cancellation and refund policy before building the payment flow, because the policy determines the data model and not the other way round. I built the flow first and then retrofitted the policy, which meant a migration and a week I did not need to spend.

If you are looking at this problem space more broadly, the operational side of tutor app development has a lot more in it than the backend: supply density by subject and time window turns out to matter more commercially than anything above. But the five things here are what will eat your engineering time.

Happy to go deeper on any of these if useful. The availability model in particular I am still not convinced I got right, and I would be interested in how others have handled the recurrence versus materialisation trade-off.