Code Monkey home page Code Monkey logo

weathermetrics's Introduction

Weather metrics

Weather metrics from Open Weather Maps API.

Design approach

  1. Given the application is a read heavy application, it is better to store the aggregated metrics than to calculate those on the fly per request. Two design choices were considered :
    1. A scheduled job to aggregate metrics for a day and store it in the database. This approach is very good when there is extremely diverse read rate and latency cannot be tolerated. This choice was ruled out for implementation because as I do not know the request diversity and it will over optimisation to pre-load all the data for all the cities if the requests are not so diverse.
    2. Reactively store the metrics on first request for a city and date. This approach was adopted to load the store reactively to avoid premature optimization by bloating up the local data store. On the down side, only the first request will face latency.
  2. Datastore is in-memory H2. However a Redis cache can be fronted.
  3. Project Lombok is used for making data classes concise.
  4. Retrofit is used as Rest Client.
  5. A Test Driven Development approach was taken
  6. Validation for the input and Integration tests are wriiten.

Building and running the application

  1. mvn clean install
  2. cd /target
  3. java -jar weathermetrics-0.0.1-SNAPSHOT-spring-boot.jar
  4. make resquest to http://localhost:8081/data?CITYNAME={cityname}

Future Enhancements

  1. Since the metrics don't change for a city for a day, it is better to cache those by LRU eviction policy.
  2. A circuit breaker could be implemented wrapping the calls to Open Weather Maps API.
  3. Currently, the validation of city is done against Open Weather Maps API. This can optimized to validate locally against a pre poplulated lists of cities.

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.