Giter Club home page Giter Club logo

codechallenge's Introduction

Campsite API

Requirements

  • JDK 8
  • Maven
  • MongoDB
  • MongoDB Compass
  • JMeter

Get the code

git clone https://github.com/pabloardiles/codechallenge.git

Assumptions

The campsite has a maximum of 10 slots (parcels) available per day.

Setup database

Start MongoDB server

./mongod --dbpath /PATH/TO/YOUR/DB/DATA --config /PATH/TO/codechallenge/db/mongod.conf

Create a Replica Set (this is required to allow mongo clients use transactions)

./mongo

And then run

> rs.initiate()
> exit

Restore database

./mongorestore /PATH/TO/codechallenge/db/dbdump/campsitedb -d campsitedb

You can now use MongoDB Compass to check the database content.

Campsite APIs

I've splitted the API in 2 separate services: campsite-availability and campsite-reservations.

campsite-availability implements the resource /api/availability which let the user search for slots availability for certain date.

campsite-reservations implements reservation management, /api/reserve, /api/cancel and /api/update resources.

Splitted this way makes campsite-availability scale independently for service availability reasons. For instance, it can be included within Container orchestration (ECS, Kubernetes, etc) or can be placed into an auto scaling group to scale out accordingly. Also it might use a read replica database to improve performance.

In order to build the services run:

mvn clean install

Deploy and run the services:

mvn spring-boot:run

Notice that campsite-availability is registered in port 8080 and campsite-reservations in port 8081.

You can take a look at their Swagger API docs at http://localhost:8080/swagger-ui.html and http://localhost:8081/swagger-ui.html

Concurrent reservations

The easiest way to see how overlapping reservations can be handled is with a JMeter test plan. Open the file /codechallenge/jmeter-test-plan/campsite-test-plan.jmx in JMeter and run the test plan. You will notice in "View Results Tree" that there will be several requests, some of them succeeded and some of them failed. Assuming that the date trying to perform the reservation is fully available at the moment (i.e. slots = 10), there should be 10 request with status code 200, and the rest should be 2 types of 409 errors:

  • "No slots left for date yyyy-mm-dd": means that the date has run out of slots.
  • "One or more dates are not available at this time. Try again later.": means that 2 o more request tried to reserve in the same date. The transaction is rolled back for requests that couldn't be served.

codechallenge's People

Contributors

pabloardiles avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.