Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Operational Analytics in Real Time with Tinybird and Retool

Three steps to create a Retool app or dashboard in minutes to display your operational analytics in real time.
Alison Davey
Developer Advocate
Jan 4, 2022
 ・ 
  min read

You ingest your data to Tinybird and run analyses; delivering realtime answers at scale through analytical API endpoints built in minutes. It’s then entirely up to you how you consume the JSON documents or CSV files resulting from the API endpoints.

If those realtime answers are insights from your operational analytics then being able to quickly and easily create an app or dashboard to display your results to colleagues makes those insights actionable. Within Tinybird, one of the ways we do this is with Retool, which is a fast way to build fully featured internal tools on top of REST APIs. With Retool you build apps by dragging and dropping pre-built components and access data from your Tinybird API Endpoints using the GET method.

Let’s look in detail at an example of using Retool to select a parameter, query an endpoint and then chart the results.

This app will plot some of the live operational data that monitors the performance of your Tinybird API endpoints and Data Sources. This is a great example of how to monitor your Tinybird account in real time, but of course you can also create apps to monitor other business data from your API endpoints so that you always know how your business is doing.

To create an app we have a three-step process:

  • ingest data to Tinybird
  • create a Tinybird API endpoint
  • create a Retool app.

1. Ingest Data to Tinybird

To create your Data Sources directly from the Tinybird UI you can ingest data from local CSV or NDJSON files, remote URLs or Kafka data streams.

Ingest data to Tinybird
Ingest data to Tinybird

But for this example, since we will be using Tinybird’s Service Data Sources you won’t need to ingest any data. These Data Sources are provided by Tinybird so that you can inspect what’s going on in your account. They give you real time stats about API calls or a log of every operation over your Data Sources, Pipes, endpoints and more.

2. Create a Tinybird API Endpoint

Every request to a pipe is logged to {% code-line %}tinybird.pipe_stats_rt{% code-line-end %} and kept in this Data Source for the last week. This service Data Source can be used to monitor pipe health. These are the columns:

Data Source schema
Data Source schema

The example API endpoint aggregates the statistics for each hour for the selected pipe.

All we need to do now is put the URL of the API endpoint into Retool.

URL of API endpoint
URL of API endpoint

3. Create a Retool app

First, copy the HTTP JSON Sample usage from the API Endpoint page in the Tinybird UI, then create a New ‘Resource Query’, and paste the URL into the ‘Resource’ RESTQueryAPI with ‘Action type’ GET. Here the ‘Resource Query’ is named ´pipe_health´.

Retool query
Retool query

Then we ‘Insert’ a ‘Select’ component onto the Retool canvas with the {% code-line %}pipe_ids{% code-line-end %} of the pipes we want to monitor as ‘Values’ and the user-friendly pipe names as ‘Labels’. The pipe names will appear in a dropdown list. The {% code-line %}pipe_ids{% code-line-end %} can be found on the VIEW API page. Now add {% code-line %}pipe_id={{select.value}}&{% code-line-end %} as a parameter to the URL in the Resource Query, either directly in the URL or a the URL parameters box:

{% code-line %}https://api.tinybird.co/v0/pipes/pipe_health.json?pipe_id={{select.value}}&token=…{% code-line-end %}

The JSON from this endpoint can then be used to create charts directly from the UI or using the full power of Plotly JSON.

Retool components
Retool components

That’s all it takes to build an app where you can interactively select your pipe and chart key performance statistics.

The beauty of this approach is that with Tinybird as the back-end, you have direct access to your operational analyses and using a low-code solution can present your results to everybody in a way that is visually impactful.

Adding more charts is straightforward. For example, we can repeat the process with the {% code-line %}tinybird.datasources_ops_log{% code-line-end %} to build charts monitoring ingestion times and rows ingested. This log tracks all operations ({% code-line %}create{% code-line-end %}, {% code-line %}append{% code-line-end %}, {% code-line %}replace{% code-line-end %}, {% code-line %}delete{% code-line-end %}, {% code-line %}truncate{% code-line-end %} and {% code-line %}rename{% code-line-end %}) performed on your Data Sources.

Here’s how the queries for the API endpoints look:

Then create each chart in Retool as before:

  • new query
  • paste in the URL
  • add a chart component
  • optionally, add selection components and the URL parameters.

The chart of ingestion times shows data for the hour prior to the date and time selected with the default value as now (here now is UTC+1). The Data Source timestamps are in UTC.

  • {% code-line %}start_date={{dateTime1.formattedValue}}{% code-line-end %}
  • {% code-line %}{{moment().format("YYYY-MM-DD HH:mm:ss")}}{% code-line-end %}

The chart of rows ingested shows data for the selected range of dates, with the default values as the last month.

  • {% code-line %}start_date={{dateRange1.value.start}}&end_date={{dateRange1.value.end}}{% code-line-end %}
  • {% code-line %}{{moment().subtract(1, "months").format("YYYY-MM-DD")}}{% code-line-end %}
  • {% code-line %}{{moment().format("YYYY-MM-DD")}}{% code-line-end %}.

This is how the resulting app looks:

You can try it out here.

If you have an interesting use case, write to us at hi@tinybird.co, sign up to Tinybird and easily build your own data apps. If you already have an account, why don’t you build an app in Retool and showcase your work in our community Slack? Looking forward to seeing you there.

Become a better data developer

Subscribe to the tinytales newsletter for monthly tips on building better data products.