https://github.com/abdulsametileri/hotel-reservation-service
A basic hotel reservation system with 2PC using pessimistic and optimistic locks in Go
https://github.com/abdulsametileri/hotel-reservation-service
2pc go optimistic-locking pessimistic-locking postgresql
Last synced: 2 months ago
JSON representation
A basic hotel reservation system with 2PC using pessimistic and optimistic locks in Go
- Host: GitHub
- URL: https://github.com/abdulsametileri/hotel-reservation-service
- Owner: Abdulsametileri
- Created: 2023-10-28T19:23:44.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-29T09:32:37.000Z (over 1 year ago)
- Last Synced: 2025-03-16T18:42:40.885Z (2 months ago)
- Topics: 2pc, go, optimistic-locking, pessimistic-locking, postgresql
- Language: Go
- Homepage: https://abdulsamet-ileri.medium.com/lets-implement-a-basic-hotel-reservation-system-with-2pc-using-pessimistic-and-optimistic-locks-in-581256d142e8
- Size: 12.7 KB
- Stars: 18
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## You can check [the blog post](https://abdulsamet-ileri.medium.com/lets-implement-a-basic-hotel-reservation-system-with-2pc-using-pessimistic-and-optimistic-locks-in-581256d142e8) for details of this project.
### Creating Reservation Table
```sql
create table reservation
(
reservation_id uuid
constraint reservation_pk
primary key,
hotel_id integer,
room_type_id integer,
start_date date,
end_date date,
status text
);
```Status can be in one of these states: pending, paid, refunded, canceled, rejected.
### Creating Room Type Inventory Table
```sql
create table room_type_inventory
(
hotel_id integer,
room_type_id integer,
date date,
total_inventory integer,
total_reserved integer
);alter table room_type_inventory
add constraint room_type_inventory_pk
primary key (hotel_id, room_type_id, date);INSERT INTO room_type_inventory (hotel_id, room_type_id, date, total_inventory, total_reserved)
VALUES
(100, 1, '2023-10-12', 2, 0),
(100, 1, '2023-10-13', 2, 0);
```### Altering Room Type Inventory Table For Optimistic Locking
```sql
alter table room_type_inventory
add version integer default 0;
```### Adding reservation db
```sql
create database reservation;
``````sql
create table reservation
(
reservation_id uuid
constraint reservation_pk
primary key,
hotel_id integer,
room_type_id integer,
start_date date,
end_date date,
status text
);
```### Adding inventory db
```sql
create database inventory;
``````sql
create table room_type_inventory
(
hotel_id integer,
room_type_id integer,
date date,
total_inventory integer,
total_reserved integer
);
```