Giter Club home page Giter Club logo

iot-backend's Introduction

IoT Backend

Build & Run

To build executable jar file, use:

./gradlew clean bootJar

To run test:

./gradlew clean test

To do both:

./gradlew clean build

To run the service:

./gradlew clean bootRun

or if you use IntelliJ, it will detect application entry point. But make sure you have a MongoDB container is running on your local environment. You can do that by:

./gradlew composeUp

Application design

The most significant property of the requirement is high write workload. I concerned about several Relational DBMS I've worked with such as MySQL, PostgreSQL but seems they're not really fit for a high write workload that have to finish in 9 hours.

Almost SQL DBMS will validate data before insert to storage space. Default isolation level of MySQL is snapshot, PostgreSQL is read committed. Of course, we can do turning for it but why don't we choose a NoSQL DBMS that has good support for high write.

So I chose MongoDB, although I haven't worked with it. But after Googling, I found that MongoDB support high write through:

About distributed database, it's risk to do in 9 hours.

Application design is simple. I have a Java web application that connect to a MongoDB to store data. The web application can scale by add more instances. The MongoDB can scale by add more resource, use sharding or replication.

Application Design

Database schema diagram

In MongoDB database, I created a collections that has schema following class AirDeviceData. I also added index for these field: deviceId, timestamp. Because these field will be used to query and sort data. For more detail, please check docker/init-mongo.js.

key name v
{"_id": 1} _id_ 2
{"deviceId": 1, "timestamp": 1} deviceId_1_timestamp_1 2

Application Design

Code structure

I divided code to several packages base on its responsibility.

Coding rule to achieve code quality

  • When I meet a class that seems complicated, I will try to refactor it by split out functionality.
  • Small class made writing unit test easier.
  • No complicated static method.
  • Refactor code base on unit test.

Summary breakdown

  • Preparation: 4 hours (research)
  • Coding: 3 hours (including tests)
  • Documentation: 2 hours
  • Verify: 1 hours
  • Grand total: 10 hours

iot-backend's People

Contributors

tranngockhoa avatar

Watchers

 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.