A high-performance distributed backend for peer-to-peer vehicle sharing. Engineered to solve race conditions in high-concurrency booking environments and optimized for O(log n) geospatial discovery.
The system follows a Three-Tier Architecture designed for scalability:
- Client Layer: React 19 + Vite (Single Page Application) for a responsive user interface.
- API Gateway: Express.js REST API handling stateless JWT authentication and request routing.
- Data Layer: MongoDB (Replica Set) with
2dsphereindexing for efficient geospatial storage.
The Problem: In a distributed system, if User A and User B book the same vehicle at t=0, standard read-modify-write logic fails, leading to data corruption.
The Solution: Implemented Optimistic Concurrency Control using MongoDB Transactions.
- Mechanism: The system uses an atomic lock
findOneAndUpdate({ _id: carId, isAvailable: true }). - Outcome: 100% Transactional Integrity. Zero double-bookings under load.
The Problem: Filtering vehicles by location using JavaScript arrays is
- Mechanism: Uses the
$nearoperator to query vehicles within a 10km radius. - Outcome: Query latency reduced from 400ms to <20ms.
| Component | Technology | Rationale |
|---|---|---|
| Backend | Node.js + Express | Non-blocking I/O for handling high concurrent requests. |
| Database | MongoDB | Flexible schema for complex Vehicle/Booking relationships. |
| Locking | Mongoose Transactions | ACID compliance for critical booking flows. |
| Frontend | React 19 + Tailwind | Component-based architecture for dynamic UI. |
| Maps | Leaflet.js | Lightweight open-source mapping for vehicle tracking. |
| Method | Endpoint | Function | Complexity |
|---|---|---|---|
POST |
/api/bookings |
Transactional Booking (Atomic Lock) | |
GET |
/api/cars/near |
Geospatial Search (Radius Query) | |
POST |
/api/auth/login |
JWT Issuance (Stateless Auth) |
- Node.js v18+
- MongoDB Local or Atlas URI
-
Clone the Repo
git clone [https://github.com/RevantPatel/VSS-React-App.git](https://github.com/RevantPatel/VSS-React-App.git) cd VSS_Project -
Install Dependencies (Root)
npm install cd client && npm install
-
Configure Environment Create a
.envfile in/server:MONGO_URI=mongodb://localhost:27017/vehicle_db JWT_SECRET=production_secret_key_v1 PORT=5000
-
Run the System
# Runs Backend (Port 5000) and Frontend (Port 5173) concurrently npm run dev
Revant Pethani
- LinkedIn: linkedin.com/in/revant-pethani
- GitHub: github.com/RevantPatel
- Email: revantpethani@gmail.com

