Real-time databases: what developers need to know
Tags: database, mongodb, postgres, opensource
Published: 2023-05-01 16:48:28

Selecting the right application database can be a challenge for developers, especially so when you need a database for building real-time applications. Real-time data has become an essential component in building user-facing experiences or creating automated decision systems, and developers need a database to match their needs.

To be effective for [real-time applications](https://www.tinybird.co/blog-posts/real-time-analytics-a-definitive-guide?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to), databases must possess exceptionally high performance, scalability, and versatility in handling complex analytical queries.

In this blog post, I’ll discuss the use cases for real-time databases, and the pros and cons of using several databases - including MongoDB, PostgreSQL, Tinybird, ClickHouse, Snowflake, Pinot, and Druid - for real-time workloads.

## What is a real-time database?
A real-time database is a database designed to handle data storage, processing, and analysis in real-time, typically reacting to and processing events or data streams as they occur. Real-time databases are optimized for low-latency query performance, high-throughput data ingestion, compute-efficient processing, and handling rapidly changing data. They are built to deliver up-to-date and accurate information, enabling both people and applications to make timely decisions based on the latest data.

### What are some use cases for a real-time database?
Real-time databases are the go-to choice for applications that require rapid data processing, analysis, and decision-making based on the most recent data generated. For example, you should choose a real-time database if you’re building any of the following use cases:

- **Real-time analytics**: Real-time databases underpin [real-time analytics](https://www.tinybird.co/blog-posts/real-time-analytics-a-definitive-guide?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to), allowing businesses to track key performance indicators, identify trends, and make data-driven decisions faster.
- **Web analytics**: Real-time databases are perfect for [analyzing web traffic and clickstreams](https://www.tinybird.co/blog-posts/google-analytics-alternative-in-3-minutes?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to) in real-time.
- **Personalization and recommendation engines**: Real-time databases can process user interactions and behavior in real time, enabling systems to offer [personalized content or recommendations during active sessions](https://www.tinybird.co/use-cases/realtime-personalization?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to).
- **Gaming**: Real-time databases can manage player data, game state, and interactions in online multiplayer games, ensuring a responsive and engaging gaming experience.
- **Sports betting**: Real-time databases can process real-time sporting events and bettor behavior to offer the [safest and most compelling betting experiences](https://www.tinybird.co/use-cases/sports-betting-gaming?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to). 
- **Location-based services**: Real-time databases can handle real-time location data from GPS devices, enabling applications to provide real-time navigation, tracking, or location-based recommendations.
- **Fraud detection and prevention**: Real-time databases can analyze incoming transactions or user activities in real time, helping to identify and prevent fraudulent activity before it causes significant damage.
- **Monitoring and alerting**: Real-time databases can quickly [process and analyze incoming data](https://www.tinybird.co/blog-posts/anomaly-detection?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to), allowing systems to [monitor and generate alerts for anomalies](https://www.tinybird.co/use-cases/anomaly-detection-alerts?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to), threshold breaches, or other critical events in real time.
- **IoT and sensor data**: Real-time databases are well-suited for handling high-velocity data streams from IoT devices and sensors, providing real-time analysis and insights into device performance, environmental conditions, and other metrics.
- **Social media and messaging applications**: Real-time databases can efficiently manage real-time interactions between users, such as messaging, likes, shares, and comments, providing an engaging user experience.
- **Inventory management**: Real-time databases can [handle merchandise inventory and transactions](https://www.tinybird.co/use-cases/smart-inventory-management?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to) in real-time to maintain a live, intelligent snapshot of actual product inventory.

## Choosing the right database for real-time applications
When you choose a database for real-time applications, you’ll need to consider several important factors. In particular, a database should have the following characteristics if it is to be useful for processing real-time data:

1. **Data warehousing and OLAP workloads**: Data warehousing and OLAP (Online Analytical Processing) workloads involve complex analytical processing, aggregation, and reporting on large volumes of data, typically for the purpose of understanding patterns, trends, and correlations in business data. For real-time applications, databases must support OLAP workloads to efficiently and quickly extract insights from data as it is generated or updated. 
2. **Scalability**: Real-time applications generate massive amounts of data. To be useful for real-time, databases must handle growing exceptionally high data volumes and query loads without sacrificing performance, by supporting horizontal scaling through sharding, partitioning, or other means.
3. **Event-driven data ingestion and processing**: Event-driven databases are designed to react to and process events as they occur in real time. Real-time databases are capable of handling streaming data ingestion at up to millions of events per second, enabling applications to quickly respond to changes in the data. This characteristic makes real-time databases especially useful for real-time analytics and monitoring.
4. **Support for complex analytics queries**: A good real-time analytics database must provide robust query capabilities, including support for advanced analytical functions, complex joins, and aggregations. Even complex analytical queries should return results within milliseconds so that users can efficiently derive insights from their data in real time.
5. **Enables sharing of insights**: A real-time database should support collaboration through APIs, integrations, and dashboards so that data and generated insights can be shared amongst team members. Stakeholders will rely on real-time databases to react quickly to changes, identify trends, and coordinate efforts more effectively, leading to better-informed strategies and more robust solutions. 
6. **Supports SQL**: SQL is a widely-used and standardized query language that facilitates collaboration among developers, data analysts, and other stakeholders. Real-time databases should support SQL so that they can more easily integrate with various tools, simplify query building, and provide an accessible way for team members to interact with and analyze data.
7. **Easy to set up/maintain**: A real-time database that is easy to set up and maintain simplifies the development and deployment process, reducing the time and resources required to get an application up and running. Furthermore, a streamlined maintenance process ensures that the database remains performant, reliable, and up-to-date with minimal effort, allowing developers to focus on improving application features and functionality rather than addressing database-related issues.

By evaluating databases based on these characteristics, you can better determine which one is the right fit for your real-time analytics needs.

## Can MongoDB be used for Real-time Analytics?
<figure><img src="https://global-uploads.webflow.com/604a2f667b2fcefbc095bfc8/6446a83684e9b4a6558a3071_AO8PoW0Op4oaVtDipYX1oA4UTZ-m2MvOxGvFiPKpez30V_7bIVh2SlAnwE8QYcyBU2MqLhm-fv8CrghmPEu-8XMPo7vN1dOc1f5KmSvxvk670mqy4UnK%3Ds1600.png" alt="A screenshot of the MongoDB website"><figcaption>MongoDB is a popular NoSQL database that has some usefulness for real-time applications.</figcaption></figure>

As a NoSQL database, [MongoDB](https://www.mongodb.com/) offers several features that make it suitable for real-time analytics applications:

1. **Scalability**: MongoDB supports horizontal scaling through sharding, which allows it to handle growing data volumes and query loads. This feature enables MongoDB to distribute data across multiple nodes, ensuring it can maintain performance even as data sizes increase.
2. **Strong support for change data capture**: MongoDB provides change streams for real-time notifications of data changes, enabling the detection and processing of events as they occur. However, it may not be as efficient as databases specifically designed for real-time data ingestion, especially when dealing with high-throughput streaming data.
3. **Powerful aggregations for complex analytic queries**: MongoDB offers a powerful aggregation framework for complex data processing and transformation tasks.
4. **It’s easy to get started**: MongoDB is known for being easy to set up and maintain, which makes it a popular choice among developers. Its flexible schema and document-based data model allow developers to quickly design and implement data structures without the need for complex schema changes.

### Limitations of MongoDB for Real-Time Analytics
While MongoDB has its advantages for real-time data processing, certain characteristics make it non-ideal for real-time use cases. In this section, we'll delve deeper into these limitations to provide a better understanding of when MongoDB might not be the ideal choice.

1. **Complex queries may take too long to respond**: MongoDB is designed for fast read and write operations but may struggle with complex analytical queries that involve large data scans, multiple joins, or aggregations. In these cases, dedicated analytical databases optimized for such workloads might offer better query performance.
2. **It lacks support for certain complex analytics queries**: MongoDB's query language and aggregation framework lack the full range of features and expressiveness provided by SQL. If your real-time analytics application requires complex SQL queries, window functions, or advanced analytics, you may find MongoDB's query capabilities limiting.
3. **The native query language limits collaboration**: MongoDB's native query language and data model may present limitations when it comes to sharing insights through APIs. MongoDB's query capabilities may not be as robust as those in SQL-based databases, which can affect the complexity and flexibility of the insights shared through APIs.
4. **It’s not built for OLAP**: MongoDB is not primarily designed for OLAP workloads, which involve complex analytical processing, aggregation, and reporting on large volumes of data. As a result, it may not provide the same performance and functionality as dedicated analytical databases. For such use cases, specialized analytical databases like ClickHouse, Pinot, or Druid might be more appropriate.
5. **It doesn’t fully support SQL**: MongoDB has limited SQL support, which could hinder collaboration among developers, data analysts, and other stakeholders who are more familiar with SQL-based tools and querying methods.
6. **The flexible schema can be hard to maintain**: A flexible schema model offers initial benefits in development but can lead to long-term maintenance challenges. Data inconsistency and lack of enforced constraints can result in difficulties in querying, aggregating, and ensuring data integrity. The evolution of data structures may require additional efforts to track and manage changes while ensuring compatibility.

## Can PostgreSQL be used for Real-time Analytics?
<figure><img src="https://global-uploads.webflow.com/604a2f667b2fcefbc095bfc8/6446a8713e2e468dff61f8b3_AO8PoW1_71iQEn2fW9gVia0ukSGnTPl3pVEEfbaTRI-zAVkvS7URfhfbFmthE91SZrG9K-_nQUp6-EEohFbfVHwX4ItPh3toLt7Csi47FRt-3RBdo-mx%3Ds1600.png" alt="A screenshot of the PostgreSQL website"><figcaption>PostgreSQL is a very popular RDBMS that can be great for starters but is not suited for the scale of most real-time applications</figcaption></figure>

While generally not optimized for real-time data, [PostgreSQL](https://www.postgresql.org/) is often used as a database for real-time analytics as it offers some benefits:

1. **Familiarity**: Most developers have used PostgreSQL at some point in their careers, and it has an extensive ecosystem of integrations.
2. **Variety of providers**: As well as being free and open-source, PostgreSQL is offered as a service by many vendors, including all of the major cloud providers and various smaller boutique vendors.
3. **Easy to start**: PostgreSQL can be incredibly easy (and cheap!) to start with, which can make it attractive as a real-time database when scalability is not a primary concern.
4. **Updates & deletes**: As a transactional database, PostgreSQL is purposefully designed to support updates & deletes, which simplifies deduplication.
5. **Popular SQL dialect**: PostgreSQL’s SQL dialect is well-understood, well-documented, and widely supported by third-party tools, making it easy to learn and work with.

### Limitations of PostgreSQL for Real-time Analytics
Despite its advantages, PostgreSQL is quite limited as a real-time database:

1. **It’s OLTP, not OLAP**: PostgreSQL may not be the best fit for Data Warehousing and OLAP workloads, since it is primarily designed as an OLTP (Online Transaction Processing) relational database system. PostgreSQL is optimized to handle high numbers of transactions and concurrent users. Its row-based storage, query optimizer, and parallel processing capabilities may not deliver optimal performance or efficiency for large-scale analytical queries over many rows of data.
2. **It is not optimized for high-frequency ingestion**: While PostgreSQL can handle event-driven data ingestion through extensions like TimescaleDB or streaming data tools like Apache Kafka, it may not be as efficient as specialized event-driven databases.
3. **Lack of API support**: While PostgreSQL is a powerful and flexible RDBMS, it does not come with built-in support for creating APIs and sharing data insights in real-time. To achieve this functionality, developers need to rely on third-party tools, libraries, and frameworks, which can add complexity and overhead to the development process.
4. **Not scalable for modern real-time use cases**: An inability to scale is perhaps the most common reason for users to migrate away from Postgres. While PostgreSQL can be a perfect starter database, scaling it can become quite complex. PostgreSQL was not originally designed for horizontal scalability, as this was not a common strategy in 1996 when it was first built. Horizontally scaling to handle higher data and query volumes can require a deep understanding of how PostgreSQL replication works, which can take too much time and energy when building real-time analytics.

## Can Tinybird be used for Real-Time Analytics?
<figure><img src="https://global-uploads.webflow.com/604a2f667b2fcefbc095bfc8/6446a8ad090073a1db5051fd_AO8PoW0PpeXXyKk4XxY4vmCQGOLsRB9i130ZXNXWLHE86b97Q3lwcuT_k30xs7Ddz71ElOoPxxp2Qnpo_VraKN_haVzC1oqaU3ZzW4ACr_Q8zHHi9kfD%3Ds1600.png" alt="A screenshot of the Tinybird website"><figcaption>Tinybird is a popular real-time data platform built on top of open source technology.</figcaption></figure>

[Tinybird](https://www.tinybird.co/product?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to), a real-time data platform built on top of ClickHouse, offers a comprehensive solution for developers building real-time analytics applications. Tinybird can be a perfect real-time database with added features that support real-time software development.

1. **Support for OLAP workloads**: Tinybird is designed to support OLAP workloads, providing fast and efficient analytical processing, aggregation, and reporting on large volumes of data. By leveraging the columnar storage and query processing capabilities of ClickHouse, Tinybird excels in extracting real-time insights from data as it is generated, making it an ideal choice for the OLAP workloads in real-time analytics applications.
2. **Highly scalable**: Tinybird is serverless and highly scalable, designed to handle growing data volumes and query loads without sacrificing performance. It supports horizontal scaling through sharding, partitioning, and other techniques, ensuring that the platform can maintain query performance even as the data and query volume grow.
3. **High-frequency ingestion from many sources**: Tinybird is built for real-time event-driven data ingestion and processing. It natively supports ingesting streaming data via popular stream platforms like Kafka, Pub/Sub, and Kinesis, as well as offering high-frequency event ingestion through an HTTP endpoint. These features make Tinybird well-suited for real-time analytics and monitoring applications.
4. **Support for complex analytics queries**: Tinybird provides robust analytical querying and, includes support for advanced analytical functions, complex joins, and aggregations. In addition, Tinybird supports real-time materialized views that shift analytical workloads away from query time for faster query response times.
5. **Built for collaboration and development**: With Tinybird, you can publish any query as a low-latency, fully-documented API, making it easy for software engineers to collaborate with data teams and other stakeholders. Additionally, Tinybird allows collaborative development within a shared Workspace, allowing team members to write code and publish APIs together.
6. **Supports SQL**: Tinybird fully supports SQL, a widely-used and standardized query language that facilitates collaboration among developers, data analysts, and other stakeholders.
7. **Zero infrastructure maintenance**: Developers can use Tinybird without setting up or maintaining any infrastructure, streamlining the development and deployment process. It reduces the time and resources required to get an application up and running, allowing developers to focus on improving application features and functionality rather than addressing database-related issues. As a managed service, Tinybird takes away all of the pain and complexity associated with running a real-time database.

## Alternative Databases for Real-Time Analytics
MongoDB, PostgreSQL, and Tinybird are popular choices for real-time databases. You can also explore alternative databases that might better suit your requirements for real-time applications. Here are some additional options to consider for real-time software development:

1. **ClickHouse**: [ClickHouse](https://github.com/ClickHouse/ClickHouse) is an open-source, OLAP database designed for real-time analytics. As a [columnar database](https://www.tinybird.co/blog-posts/when-to-use-columnar-database?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to), it offers high write and query performance, making it suitable for large-scale data processing. ClickHouse supports parallel and distributed processing, which helps in handling massive datasets and improving query speed. It also provides extensive SQL support, including support for complex joins and subqueries, which can be beneficial in real-time analytics scenarios that require more advanced querying capabilities. Originally designed to handle web clickstream data, ClickHouse adds many new features to its SQL dialect, making it especially useful for working with time-series and web event data streams.
2. **Apache Pinot**: [Pinot](https://github.com/apache/pinot) is an open-source, distributed, and columnar database written in Java and designed specifically for real-time analytics. Developed by LinkedIn, it is designed to handle large-scale, low-latency OLAP queries. Pinot has support for a few streaming data sources, such as Kafka, and offers features like real-time indexing, horizontal scaling, and support for complex data types. Pinot has very limited support for JOINs. It uses the MySQL dialect for queries, which means it benefits from good support of external query-building tools, but lacks modern language features that help when working with real-time data.
3. **Apache Druid**: [Druid](https://github.com/apache/druid) is another open-source, distributed, and columnar data store designed for real-time analytics. Druid excels in handling time-series data and provides low-latency querying capabilities. It features a flexible ingestion model, support for approximate queries, and horizontal scalability. Druid’s native query language is JSON-based, but it provides a custom SQL dialect on top, known as ‘Druid SQL’.
4. **Snowflake**: [Snowflake](https://www.snowflake.com/en/) is a cloud-based data warehouse that provides a scalable, flexible, and cost-effective solution for storing and processing large volumes of structured and semi-structured data. It excels at supporting internal reporting and business intelligence use cases with support for complex analytical queries, and seamless integration with various data processing and visualization tools. However, it is can struggle with real-time data ingestion, and scaling to handle the concurrency demands of user-facing applications can be prohibitively expensive.

## Comparison of popular real-time databases
Refer to the table below for a high-level comparison of different databases for real-time applications. Note that this table is meant as a high-level reference to compare these databases. Actual feature coverage will depend on specific use case and implementation.

<figure><img src="https://global-uploads.webflow.com/604a2f667b2fcefbc095bfc8/6446c8c8d5111f219535fe07_Copy%20of%20Table%20for%20real-time%20databases%20blog.png" loading="lazy" alt=""><figcaption>Comparing various real-time databases</figcaption></figure>

## Conclusion
Software and data engineers working with real-time data must select the right database for real-time applications, as the chosen database directly impacts the performance, scalability, and versatility of the entire system. MongoDB and PostgreSQL are popular application databases with features that may make them suitable for certain use cases, but they’re generally not the best choice for every real-time analytics scenario.

[Tinybird](https://www.tinybird.co/?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to), on the other hand, stands out as a strong contender for software developers building real-time analytics applications. By leveraging the power of an alternative, open-source real-time database in ClickHouse, Tinybird offers high-frequency data ingestion, powerful SQL support, and real-time querying capabilities that are essential for real-time development. In addition to its real-time bonafides, Tinybird is easy to start with, requires zero infrastructure setup or maintenance, and makes data sharing and collaboration simple through it’s one-click API publication workflow.

By meeting the outlined criteria for real-time analytics databases, such as data warehousing and OLAP workloads support, scalability, event-driven data ingestion and processing, support for complex analytics queries, and SQL support, Tinybird proves to be a compelling choice for developers. Its ability to simplify setup and maintenance while enabling efficient sharing of insights further underscores its suitability for real-time analytics applications.

To learn more about how to build real-time analytics APIs with Tinybird, check out these resources:

- [Docs - Tinybird Documentation](https://www.tinybird.co/docs?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to)
- [Blog - Real-time analytics, a definitive guide](https://www.tinybird.co/blog-posts/real-time-analytics-a-definitive-guide?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to)
- [Screencast - The Tinybird Basics in 3 minutes](https://youtu.be/cvay_LW685w)
- [Guide - Best practices for faster SQL queries](https://www.tinybird.co/docs/guides/best-practices-for-faster-sql.html?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to)
- [Blog - Publish SQL-based API endpoints on NGINX log analytics](https://www.tinybird.co/blog-posts/nginx-log-analysis?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to)
- [Talk - Building fast APIs, faster, over streaming data at scale](https://www.tinybird.co/blog-posts/ddnyc-talk-fast-apis-faster-at-scale?utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to)

Ready to experience the industry-leading real-time analytics platform? [Try Tinybird today](https://www.tinybird.co/signup?referrer=devto&utm_source=dev.to&utm_medium=referral&utm_campaign=q2-2023-dev.to), for free. Get started with the Build Plan - which is more than enough for most simple projects and has no time limit - and upgrade as you scale.