Build a Ride Sharing Application with Superblocks and CockroachDB

The Superblocks Team
+2

Multiple authors

March 7, 2023

5 min Read

Copied

What is CockroachDB

CockroachDB is a distributed SQL database that offers several benefits over other databases:

  • Scalability: Designed to scale horizontally, meaning you can add more nodes to handle increasing amounts of data and traffic.
  • Resilience: Uses a consensus algorithm to ensure that data is stored in multiple locations, so if one node fails, the data can be retrieved from another.
  • Simplicity: Familiar SQL interface, which makes it easy for developers to use.
  • Global distribution: Automatic data distribution across multiple geographic locations, which is useful for applications with users in different parts of the world.

CockroachDB comes with a generous free tier which can be used to build a Superblocks Application in minutes.

This post will look at an Internal Application allowing Support team members to search all active rides and track them in real time.

Connect Superblocks to CockroachDB

Superblocks provides native integration into CockroachDB, making it quick and easy to build Applications, Workflows and Scheduled Jobs that read and write to CockroachDB. By combining CockroachDB’s VPC peering alongside the Superblocks Agent, you’re able to keep all your customer data inside your own VPC. The Superblocks Agent is lightweight, and  can be run as a docker container within your private network ensuring secure access to your data.

Building Applications on CockroachDB data

In a recent Webinar, Shy Ruparel and Aydrian Howard built out a ride-sharing application showing the live progress of rides from the CoackroachDB sample database and workload called MovR. With just a handful of components and a couple of APIs, users are able to filter a table to show all currently active journeys. When a journey is selected, a map component centers on the journey and tracks the journey’s progress live by using Timers.

Display table data from CockroachDB

With the CockroachDB integration setup an API can quickly be created to select data from the MovR database. The data is automatically returned from APIs as JSON making it easy to drop straight into a Table. Using Drag and Drop, a table component can be added to the canvas. To connect the dataset to the table, the API response can be selected in the Table Data property. A great time saving feature is that the table’s columns will automatically update to match the returned JSON data, no need to manually configure the columns!

Add a live map component with event handlers

To display individual rides within a map, a few steps need to be completed. First an API needs to be created to pull the selected ride’s details from CockroachDB. Javascript can be used within SQL queries to dynamically set values, in this case, to grab the selected row’s ID from the Table.

Next is to connect this API to the Table’s onRowClicked event handler so that the API is run when a user selects a row.  Event handlers are the binding glue between the frontend UI and the backend APIs.  Each component comes with a variety of event handlers giving developers the freedom to build out complex Applications.

With the backend API created and returning ride data based on the selected ride, a Map component can now be dragged onto the canvas. The API contains a Python step that formats the data returned from CockroachDB into one what is suitable for use within the map. Developers are able to  incorporate custom business logic with both Python and Javascript code.

The Map can now be configured with both an initial location, to centralize the map, and Default markers to track the journey.

Bring real time updates with Timers

Using Timers we can easily make the map dynamic by calling the buildMap API at regular intervals so that journeys can be tracked on the Map in real time. Timers have a single Event Handler named onFire which allows any number of actions or APIs to be run at set intervals, this is all easily configurable within the UI. In this case, the Timer only needs to run the buildMap API and can do so every five seconds.

And that’s it! A usable Internal Application allowing Support team members to search all active rides and track them, all it took was CockroachDB, a handful of components and a couple of APIs!

Workflows and Scheduled Jobs

As with all Superblocks Integrations their use isn't limited to building out Applications, they can also be used to build Workflows and Scheduled Jobs.

With Workflows, build reusable APIs that can be allied from Applications or other third-party services to surface data from CockroachDB

Scheduled Jobs are great for sending reports out by perhaps Slack or Email of business health.

Try out the CockroachDB integration with Superblocks

Superblocks has helped hundreds of developers save 100s of hours of time both in building and in using internal applications.

In this blog we’ve focused on a particular example of how to use Superblocks with CockroachDB to build an application but keep in mind that Superblocks is also great for building Workflows and Scheduled Jobs. The workflows are valuable because the reusable APIs apllied from other apps or third-party surfaces can be used to surface data from CockroachDB. And the scheduled jobs are helpful for sharing business health reports via Slack or Email.

To learn more about how to create internal Applications, Jobs, and Workflows with Superblocks view our documentation. Try creating your first application today with a free 14-day trial​​.

Stay tuned for updates

Get the latest Superblocks news and internal tooling market insights.

You've successfully signed up
The Superblocks Team
+2

Multiple authors

Dec 13, 2023