Giter Club home page Giter Club logo

stock-api's Introduction

Stock APIs

Motivation

This project is an assignment. Implemented code would be a nice example of Stock data APIs.

Features

Stock APIs provides

  • Create, update and fetch stock data using HTTP endpoints.

  • Used AKKA to achieve fine grained control of the consistency level for reads and writes.

  • Scalable and highly available NoSQL data store.

  • Made a sample UI, go to the frontend-angular-app directory and follow the readme.

sequence-diagram screenshot

How to run

Prerequisite
  • JDK 1.8 (Tested with Oracle JDK)

  • Maven 3.6.x+

  • Docker (18.09.2), Docker Compose (1.23.2)

Run Cassandra in Docker
$ docker-compose up
Build
$ mvn clean compile install
Run
$ java -jar target/stock-api-1.0.0.jar

or

$ mvn spring-boot:run
Quick test

Create Stock

curl -X POST localhost:8080/api/stocks \
-H 'Content-Type: application/json' \
-d '{ "name": "Apple", "currentPrice": 10.0 }'

example response

{"id":"b9ee0544-1a4d-4ae5-b22e-3a05e4c4c6f1"}

Get first page of Stocks

curl -X GET localhost:8080/api/stocks \
-H 'Content-Type: application/json'

example response

{
   "data":[
      {
         "id":"b9ee0544-1a4d-4ae5-b22e-3a05e4c4c6f1",
         "name":"Apple",
         "currentPrice":10.0,
         "lastUpdate":1563738072242
      }
   ],
   "pageNo":0,
   "pageSize":10
}

Get second page of Stocks

curl -X GET 'http://localhost:8080/api/stocks?pageNo=1&pageSize=10' \
-H 'Content-Type: application/json'

example response

{
   "data":[

   ],
   "pageNo":1,
   "pageSize":10
}

Get stock by id

curl -X GET 'http://localhost:8080/api/stocks/b9ee0544-1a4d-4ae5-b22e-3a05e4c4c6f1' \
-H 'Content-Type: application/json'

example response

{
   "id":"b9ee0544-1a4d-4ae5-b22e-3a05e4c4c6f1",
   "name":"Apple",
   "currentPrice":10.0,
   "lastUpdate":1563738072242
}

Update Stock by id

curl -X PUT 'http://localhost:8080/api/stocks/b9ee0544-1a4d-4ae5-b22e-3a05e4c4c6f1' \
-H 'Content-Type: application/json' \
-d '{ "name": "Apple Inc", "currentPrice": 20.0 }'

example response

{
   "id":"b9ee0544-1a4d-4ae5-b22e-3a05e4c4c6f1",
   "name":"Apple Inc",
   "currentPrice":20.0,
   "lastUpdate":1563741056100
}

Design Decisions

  • According to assignment, Stock Id should be number.

    • Choose String instead of long / int. Type 4 UUID create hard to predict id, better than predictable number id.

    • Usually better that number but has it’s own flaw. Just a choice.

  • According to assignment, the list of stocks should be created in memory on application startup.

    • Did not do it because in-memory cache could cause cache consistency problem during scaling.

    • Added dummy data on dev profile to demo purpose.

  • Authentication and authorization is not taking into consideration.

  • AKKA creates mailbox (queue) that perform action on data. Provides fine grained control over reads and writes of current price of stocks.

  • NoSQL data store is an obvious choice. Cassandra provides high scalability and availability.

  • Choose Reactive REST endpoint with Spring WebFlux because AKKA is already reactive and it consumes less resource.

Development

How to run tests
How to run unit tests

To run the unit tests, execute the following commands

mvn clean test-compile test
How to run integration tests

To run the integration tests, execute the following commands

mvn clean test-compile verify -DskipTests=true
How to run both unit tests and integration tests

To run the integration tests, execute the following commands

mvn clean test-compile verify
How to run pitest

To run the mutation tests, execute the following commands

mvn clean test-compile test
mvn org.pitest:pitest-maven:mutationCoverage

Improvements to make

  • Improve architectural design, completed the project in 12 hours.

  • Code improvements

    • Type casting in REST controller and in StockActor is not nice, need to fix it. First time working with AKKA and WebFlux.

    • Use Cassandra with reactive spring repository.

  • Build docker image (plugin already added in the pom).

  • Generate and check OWASP report.

  • Improve code coverage, e.g. adding end-to-end tests.

Licensed under the MIT License, see the LICENSE file for details.

stock-api's People

Contributors

mmahmoodictbd avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

akterstack guseyn

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.