This application is built to order the investment products
- Spring Boot 2.6.0
- Java 8
- H2
- JPA
- Maven
- Junit5
Product
fields : productId, title, totalInvestmentAmt, currentInvestmentAmt, noOfInvestors, status, startAt, finishAt
Order
fields : orderId, userId, productId, title, totalInvestmentAmt, investAmt, createdAt
- Create : Create a
Product
- Get : Fetch
Product
details - Get : Fetch
Product
details for a specific duration
- Create : Create an
Order
๐จ HTTP Header : 'X-User-ID' - Get : Fetch
Order
details for a givenUser
๐จ HTTP Header : 'X-User-ID'
In this project, a sample data set is already included in H2 database
INSERT INTO Product(product_id, title, total_investment_amt, current_investment_amt, no_of_investors, status, start_at, finish_at) VALUES (1, 'annuity', 1000, 100, 10, true, '2021-01-01', '2021-12-31')
INSERT INTO Product(product_id, title, total_investment_amt, current_investment_amt, no_of_investors, status, start_at, finish_at) VALUES (2, 'bond', 2000, 500, 20, true, '2021-05-01', '2021-12-31')
INSERT INTO Product(product_id, title, total_investment_amt, current_investment_amt, no_of_investors, status, start_at, finish_at) VALUES (3, 'saving bond', 5000, 2000, 5, false, '2021-03-01', '2021-05-01')
...
curl --location --request GET 'http://localhost:8080/api/products/'
curl --location --request POST 'http://localhost:8080/api/order/' \
--header 'X-USER-ID: 1' \
--header 'Content-Type: application/json' \
--data-raw '{
"productId": "1",
"investAmt": 100
}'
curl --location --request GET 'http://localhost:8080/api/order/' \
--header 'X-USER-ID: 1'
When a number of users are trying to order investment products at the same time, a huge bottleneck could be an issue about accessing data and reliability of the system.
Synchronized methods
is being used as an implicit lock to allow only one thread to execute at any given time.
Therefore, when multiple threads executing simultaenously, and access the same resource at the same time,
thread-safe
can be acheived to resolve inconsistency problems by allowing only one thread at a time.