Drone management database design

Viewed 155

Overview

I’m currently building a prototype to track and control a fleet of drones.

The prototype consists of a service and a web app. In the web app, the location of each drone is displayed in real-time on a map and the user can issue basic commands to each of these drones. The service is automated and can also issue commands to each of the drones at random times when certain conditions occur.

I am using HiveMQ (an MQTT broker) to facilitate communication between drones, the web app and the service. The web app and the service are both subscribed to the 'telemetry' topic to receive real-time data about the network of drones. The broker will store the telemetry data for each drone directly into a database through the use of HiveMQ's extension functionality.

Specific commands can only be executed if certain criteria are met.

For example: To issue an 'execute mission' command to a drone the service or the web app will make a call to an API. The API will:

  1. Check the drone is not currently on a mission (drone status value must be idle)
  2. Check weather conditions are acceptable in the area the mission is to occur

(Note by 'mission' I mean a drone fly's to a series of set locations autonomously).

If conditions aren't met a response indicating this will be returned to the requester (web app or service). If conditions are met the API will issue the command to the appropriate drone via the MQTT broker and send a response to the requester.

Requirements

I need a storage mechanism that meets the following criteria:

  1. I need to ensure that a race condition does not occur between the web app and the service. That is if a request to issue a command to a drone is being made by the web app, a request made by the service in this time should be automatically rejected.
  2. Drone status between the service and the web app are not synchronous, as a result, they need a synchronized point to check a drones status.
  3. Drones will update their status every second, and API call's to issue commands will be made every 10 - 30 seconds. There will be 5 drones in this prototype but I would like a solution that can scale to 50 drones.

Considered Solution

My solution would be that of a relational database - using a separate table with a 'request_lock' field, this field uses a row-level lock.

When an API call is made it checks if this field is true, if true the request is rejected. If it is false it sets the field to true performs the necessary condition checks and then sets the 'request_lock' field to false when once the command has reached the drone.

I am concerned the status update frequency from each drone does not fit a relational database model and won't scale well. Am I on the right track, or should I be looking to include a NoSQL database in some way to handle status updates?

Thank you to anyone who takes the time to answer.

1 Answers

There are a lot of questions here, so I'll try to pick what seems to be most important:

I am concerned the status update frequency from each drone does not fit a relational database model ..

Should I use a relational or non-relational database?

First, let's calculate the maximum number of drone status updates, per second.

Drones will update their status every second, and API call's [sic] to issue commands will be made every 10 - 30 seconds. There will be 5 drones in this prototype but I would like a solution that can scale to 50 drones.

  • 50 drones * 1 drone-update per second = 50 drone-updates per second
  • 50 drones * (10 / 60) drone-commands per second = 8.3 drone-commands per second

So, can a relational database handle ~60 queries per second?

Yes. Assuming reasonable query complexity, this is within the ability of a traditional relational database. I would not expect the database to need extraordinary system resources, either.

If you'd like to confirm this level of performance with a benchmark, I'd recommend a tool like pgbench.

Related