← All writing

· 3 min read

Alquileres Temporales: cron jobs, two caches and a lossy refactor

How a short-term rental platform in Rosario handled expiring bookings, availability caching and an auth swap, with the lessons from its own docs.

Alquileres Temporales was a booking platform for short-term apartment rentals in Rosario and Firmat, Argentina. Guests searched, booked, uploaded an identity document and paid through Mercado Pago, and the owner ran everything from an admin dashboard. The project is discontinued. The screenshots in this post come from a local copy running on invented apartments and guests, not from real data. This is a look at the parts worth writing about.

Landing page with the search form over a Rosario skyline

The shape of it

Next.js 16 with the App Router and React 19, in TypeScript. Pages are Server Components, mutations are Server Actions, and TanStack Query handles server state in the browser. Data lives in Postgres on Neon behind Prisma. Clerk handles sign-in, Vercel Blob stores the guest documents, Resend sends the email, and Mercado Pago takes the payments.

Bookings that have to let go

A booking starts as pending and holds its dates. If the guest never finishes, those dates have to come back, and the identity document they uploaded has to go away so personal data does not pile up in storage.

Nothing in a serverless app runs on its own, so the answer is Vercel Cron. The project has eight scheduled jobs:

  • every 15 minutes, mark pending bookings that expired
  • every 30 minutes, remove expired bookings and their files
  • every hour, sync external calendars such as Airbnb and Booking.com, mark finished stays as completed, and drop old blocked dates
  • a few times a day, clean up failed reservations and paid bookings that were never confirmed
  • on Mondays at 09:00, send a weekly booking report

Admin bookings table with status filters

Two caches, one calendar

An availability calendar is the worst thing to cache: it has to be fast on the first visit and correct a second later.

The apartment endpoint tells the CDN to keep a response for five minutes and to serve a stale one for up to an hour while it refreshes in the background, and tells browsers not to cache it at all. On the client, the apartment and its calendar use TanStack Query with a stale time of zero, so they refetch on mount and on window focus. When the owner blocks dates, a Server Action calls revalidatePath to clear the CDN.

The docs record the gap this left. revalidatePath clears the Next.js and CDN caches but not the browser's query cache, so a guest with the page already open kept seeing old availability until a refresh. The fix is to run mutations through hooks that invalidate both.

A refactor that quietly lost behaviour

Moving every booking action behind one tracking middleware was meant to be a cleanup. A side-by-side comparison of the old and new actions found otherwise. The new confirm action had lost its transaction, its check that the booking was not already confirmed, and the step that blocks the dates, which made double bookings possible. The new cancel action only worked for admins, where guests had been able to cancel their own bookings. The comparison ended with a list of what to restore. Writing that comparison down, action by action, was worth more than the refactor.

Booking step for uploading identity documents, with placeholder images

Swapping the auth provider

The project started on NextAuth v5 (Auth.js) and moved to Clerk to fix problems seen in production. The migration plan counts more than 120 files that call auth(), which is why it was written in phases: install and configure first without breaking anything, then replace the core configuration, then move the callers.

Where it ended

The booking logic, the cron setup and the caching notes are all in a private GitHub repository. The app is offline.