<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shawn Adams</title>
    <description>The latest articles on DEV Community by Shawn Adams (@shawn).</description>
    <link>https://dev.to/shawn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F196019%2F02016edf-8d14-4307-9ef2-8b07b4cf4867.jpeg</url>
      <title>DEV Community: Shawn Adams</title>
      <link>https://dev.to/shawn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shawn"/>
    <language>en</language>
    <item>
      <title>Benchmarking Elasticsearch and Rockset: Rockset achieves up to 4X faster streaming data ingestion</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Wed, 03 May 2023 07:00:00 +0000</pubDate>
      <link>https://dev.to/rocksetcloud/benchmarking-elasticsearch-and-rockset-rockset-achieves-up-to-4x-faster-streaming-data-ingestion-5f6h</link>
      <guid>https://dev.to/rocksetcloud/benchmarking-elasticsearch-and-rockset-rockset-achieves-up-to-4x-faster-streaming-data-ingestion-5f6h</guid>
      <description>&lt;p&gt;Rockset is a database used for real-time search and analytics on streaming data. In scenarios involving analytics on massive data streams, we’re often asked the maximum throughput and lowest data latency Rockset can achieve and how it stacks up to other databases. To find out, we decided to test the streaming ingestion performance of Rockset’s next generation cloud architecture and compare it to open-source search engine &lt;a href="https://rockset.com/comparisons/elasticsearch-vs-rockset/"&gt;Elasticsearch&lt;/a&gt;, a popular sink for Apache Kafka.&lt;/p&gt;

&lt;p&gt;For this benchmark, we evaluated Rockset and Elasticsearch ingestion performance on throughput and data latency. Throughput measures the rate at which data is processed, impacting the database's ability to efficiently support high-velocity data streams. Data latency, on the other hand, refers to the amount of time it takes to ingest and index the data and make it available for querying, affecting the ability of a database to provide up-to-date results. We examine latency at the 95th and 99th percentile, given that both databases are used for production applications and require predictable performance.&lt;/p&gt;

&lt;p&gt;We found that Rockset beat Elasticsearch on both throughput and end-to-end latency at the 99th percentile. &lt;strong&gt;Rockset achieved up to 4x higher throughput and 2.5x lower latency than Elasticsearch&lt;/strong&gt; for streaming data ingestion.&lt;/p&gt;

&lt;p&gt;In this blog, we’ll walk through the benchmark framework, configuration and results. We’ll also delve under the hood of the two databases to better understand why their performance differs when it comes to search and analytics on high-velocity data streams.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why measure streaming data ingestion?
&lt;/h2&gt;

&lt;p&gt;Streaming data is on the rise with over &lt;a href="https://kafka.apache.org/powered-by"&gt;80% of Fortune 100&lt;/a&gt; companies using Apache Kafka. Many industries including gaming, internet and financial services are mature in their adoption of event streaming platforms and have already graduated from data streams to torrents. This makes it crucial to understand the scale at which eventually consistent databases Rockset and Elasticsearch can ingest and index data for real-time search and analytics.&lt;/p&gt;

&lt;p&gt;In order to &lt;a href="https://rockset.com/blog/the-rise-of-streaming-data-and-the-modern-real-time-data-stack/"&gt;unlock streaming data&lt;/a&gt; for real-time use cases including personalization, anomaly detection and logistics tracking, organizations pair an event streaming platform like Confluent Cloud, Apache Kafka and Amazon Kinesis with a downstream database. There are several advantages that come from using a database like Rockset or Elasticsearch including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Incorporating historical and real-time streaming data for search and analytics&lt;/li&gt;
&lt;li&gt;Supporting transformations and rollups at time of ingest&lt;/li&gt;
&lt;li&gt;Ideal when data model is in flux&lt;/li&gt;
&lt;li&gt;Ideal when query patterns require specific indexing strategies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Furthermore, many search and analytics applications are &lt;a href="https://rockset.com/blog/the-rise-of-streaming-data-and-the-modern-real-time-data-stack/"&gt;latency sensitive&lt;/a&gt;, leaving only a small window of time to take action. This is the benefit of databases that were designed with streaming in mind, they can efficiently process incoming events as they come into the system rather than go into slow batch processing modes.&lt;/p&gt;

&lt;p&gt;Now, let’s jump into the benchmark so you can have an understanding of the streaming ingest performance you can achieve on Rockset and Elasticsearch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using RockBench to measure throughput and latency
&lt;/h2&gt;

&lt;p&gt;We evaluated the streaming ingest performance of Rockset and Elasticsearch on &lt;a href="https://github.com/rockset/rockbench"&gt;RockBench&lt;/a&gt;, a benchmark that measures the peak throughput and end-to-end latency of databases.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://rockset.com/whitepapers/evaluating-data-latency-for-real-time-databases/"&gt;RockBench&lt;/a&gt; has two components: a data generator and a metrics evaluator. The data generator writes events every second to the database; the metrics evaluator measures the throughput and end-to-end latency or the time from when the event is generated until it is queryable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HgghKURe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/15Ow4ZMvYjQM5X9YO2f22R/58295c780c230e8e4019d456882b3d6a/Screen_Shot_2023-05-03_at_6.48.55_AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HgghKURe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/15Ow4ZMvYjQM5X9YO2f22R/58295c780c230e8e4019d456882b3d6a/Screen_Shot_2023-05-03_at_6.48.55_AM.png" alt="Multiple instances of the benchmark connect to the database under test." width="800" height="439"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Multiple instances of the benchmark connect to the database under test.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The data generator generates documents, each document is the size of 1.25KB and represents a single event. This means that 8,000 writes is equivalent to 10 MB/s.&lt;/p&gt;

&lt;p&gt;Peak throughput is the highest throughput at which the database can keep up without an ever-growing backlog. For this benchmark, we continually added ingested data in increments of 10 MB/s until the database could no longer sustainably keep up with the throughput for a period of 45 minutes. We determined the peak throughput as the increment of 10 MB/s above which the database could no longer sustain the write rate.&lt;/p&gt;

&lt;p&gt;Each document has 60 fields containing nested objects and arrays to mirror semi-structured events in real life scenarios. The documents also contain several fields that are used to calculate the end-to-end latency:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;_id&lt;/code&gt;: The unique identifier of the document&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;_event_time&lt;/code&gt;: Reflects the clock time of the generator machine&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;generator_identifier&lt;/code&gt;: 64-bit random number &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;_event_time&lt;/code&gt; of that document is then subtracted from the current time of the machine to arrive at the data latency of the document. This measurement also includes round-trip latency—the time required to run the query and get results from the database back to the client. This metric is published to a Prometheus server and the p50, p95 and p99 latencies are calculated across all evaluators.&lt;/p&gt;

&lt;p&gt;In this performance evaluation, the data generator inserts new documents to the database and does not update any existing documents.&lt;/p&gt;

&lt;h2&gt;
  
  
  RockBench Configuration &amp;amp; Results
&lt;/h2&gt;

&lt;p&gt;To compare the scalability of ingest and indexing performance in Rockset and Elasticsearch, we used two configurations with different compute and memory allocations. We selected the &lt;a href="https://learn.microsoft.com/en-us/azure/virtual-machines/edv4-edsv4-series"&gt;Elasticsearch Elastic Cloud cluster configuration&lt;/a&gt; that most closely matches the CPU and memory allocations of the Rockset virtual instances. Both configurations made use of &lt;a href="https://rockset.com/blog/star-schema-benchmark-intel-ice-lake/"&gt;Intel Ice Lake&lt;/a&gt; processors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JHdXS5AM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/2gesK56ihPe0ISpdrMctl0/2d46a6fbb384f1175d41159d0d7cc6d7/Screen_Shot_2023-05-03_at_10.06.07_AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JHdXS5AM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/2gesK56ihPe0ISpdrMctl0/2d46a6fbb384f1175d41159d0d7cc6d7/Screen_Shot_2023-05-03_at_10.06.07_AM.png" alt="Table of the Rockset and Elasticsearch configurations used in the benchmark." width="800" height="443"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Table of the Rockset and Elasticsearch configurations used in the benchmark.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The data generators and data latency evaluators for Rockset and Elasticsearch were run in their respective clouds and the US West 2 regions for regional compatibility. We selected Elastic Elasticsearch on Azure as it is a cloud that offers Intel Ice Lake processors. The data generator used Rockset’s write API and &lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/8.7/docs-bulk.html"&gt;Elasticsearch’s bulk API&lt;/a&gt; to write new documents to the databases.&lt;/p&gt;

&lt;p&gt;We ran the Elasticsearch benchmark on the Elastic Elasticsearch managed service &lt;a href="https://www.elastic.co/guide/en/elasticsearch///reference/master/release-notes-8.7.0.html"&gt;version v8.7.0&lt;/a&gt;, the newest stable version, with 32 primary shards, a single replica and availability zone. We tested several different refresh intervals to tune for better performance and landed on a refresh interval of 1 second which also happens to be the default setting in Elasticsearch. We settled on a 32 primary shard count after evaluating performance using 64 and 32 shards, following the &lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/size-your-shards.html#shard-size-recommendation"&gt;Elastic guidance&lt;/a&gt; that shard size range from 10 GB to 50 GB. We ensured that the shards were equally distributed across all of the nodes and that rebalancing was disabled.&lt;/p&gt;

&lt;p&gt;As Rockset is a SaaS service, all cluster operations including shards, replicas and indexes are handled by Rockset. You can expect to see similar performance on standard edition Rockset to what was achieved on the RockBench benchmark.&lt;/p&gt;

&lt;p&gt;We ran the benchmark using batch sizes of 50 and 500 documents per write request to showcase how well the databases can handle higher write rates. We chose batch sizes of 50 and 500 documents as they mimic the load typically found in incrementally updating streams and high volume data streams.&lt;/p&gt;

&lt;h3&gt;
  
  
  Throughput: Rockset sees up to 4x higher throughput than Elasticsearch
&lt;/h3&gt;

&lt;p&gt;Peak throughput is the highest throughput at which the database can keep up without an ever-growing backlog. The results with a batch size of 50 showcase that Rockset achieves up to 4x higher throughput than Elasticsearch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e9YlyKjS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/2D2YX5J5NidAtPcjgzos9q/d7880a860d677d952f1b0dfc4b5a14d5/Screen_Shot_2023-05-03_at_10.07.11_AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e9YlyKjS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/2D2YX5J5NidAtPcjgzos9q/d7880a860d677d952f1b0dfc4b5a14d5/Screen_Shot_2023-05-03_at_10.07.11_AM.png" alt="Table of the peak throughput and p95 latency of Elasticsearch and Rockset. Databases were evaluated using vCPU 64 and vCPU 128 instances and a batch size of 50." width="800" height="438"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Table of the peak throughput and p95 latency of Elasticsearch and Rockset. Databases were evaluated using vCPU 64 and vCPU 128 instances and a batch size of 50.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The results with a batch size of 50 showcase that Rockset achieves up to 4x higher throughput than Elasticsearch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1HLIMzeu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/7JChqpqSoWMzUnV8J5Hqfj/2df8aa0bfbd1c2323c8cd917e7fd8ce5/Screen_Shot_2023-05-03_at_10.08.31_AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1HLIMzeu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/7JChqpqSoWMzUnV8J5Hqfj/2df8aa0bfbd1c2323c8cd917e7fd8ce5/Screen_Shot_2023-05-03_at_10.08.31_AM.png" alt="Table of the peak throughput and p95 latency of Elasticsearch and Rockset. Databases were evaluated using vCPU 64 and vCPU 128 instances and a batch size of 500." width="800" height="442"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Table of the peak throughput and p95 latency of Elasticsearch and Rockset. Databases were evaluated using vCPU 64 and vCPU 128 instances and a batch size of 500.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With a batch size of 500, Rockset achieves up to 1.6x higher throughput than Elasticsearch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zex8vPLp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/34Qhyup4hjb5L9Jv7AM3nt/88625b18e4bc3cf516feebe67a4822c5/Screen_Shot_2023-05-03_at_10.10.05_AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zex8vPLp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/34Qhyup4hjb5L9Jv7AM3nt/88625b18e4bc3cf516feebe67a4822c5/Screen_Shot_2023-05-03_at_10.10.05_AM.png" alt="Graph of the peak throughput of Elasticsearch and Rockset using batches of 50 and 500. Databases were evaluated on 64 and 128 vCPU instances. Higher throughput indicates better performance." width="800" height="446"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Graph of the peak throughput of Elasticsearch and Rockset using batches of 50 and 500. Databases were evaluated on 64 and 128 vCPU instances. Higher throughput indicates better performance.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One observation from the performance benchmark is that Elasticsearch handles larger batch sizes better than smaller batch sizes. The &lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-indexing-speed.html#_use_bulk_requests"&gt;Elastic documentation&lt;/a&gt; recommends using bulk requests as they achieve better performance than single-document index requests. In comparison to Elasticsearch, Rockset sees better throughput performance with smaller batch sizes as it’s designed to process incrementally updating streams.&lt;/p&gt;

&lt;p&gt;We also observe that the peak throughput scales linearly as the amount of resources increases on Rockset and Elasticsearch. Rockset consistently beats the throughput of Elasticsearch on RockBench, making it better suited to workloads with high write rates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Latency: Rockset sees up to 2.5x lower data latency than Elasticsearch
&lt;/h3&gt;

&lt;p&gt;We compare Rockset and Elasticsearch end-to-end latency at the highest possible throughput that each system achieved. To measure the data latency, we start with a dataset size of 1 TB and measure the average data latency over a period of 45 minutes at the peak throughput.&lt;/p&gt;

&lt;p&gt;We see that for a batch size of 50 the maximum throughput in Rockset is 90 MB/s and in Elasticsearch is 50 MB/s. When evaluating on a batch size of 500, the maximum throughput in Rockset is 110 MB/s and Elasticsearch is 80 MB/s.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hjYUj90Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/47QToffvj14Z5jOqRwwX9i/3afc5236b2a63c98c68bea41ccfe364b/Screen_Shot_2023-05-03_at_10.11.04_AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hjYUj90Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/47QToffvj14Z5jOqRwwX9i/3afc5236b2a63c98c68bea41ccfe364b/Screen_Shot_2023-05-03_at_10.11.04_AM.png" alt="Table of the 50th, 95th and 99th percentile data latencies on batch sizes of 50 and 500 in Rockset and Elasticsearch. Data latencies are recorded for 128 vCPU instances." width="800" height="440"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Table of the 50th, 95th and 99th percentile data latencies on batch sizes of 50 and 500 in Rockset and Elasticsearch. Data latencies are recorded for 128 vCPU instances.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;At the 95th and 99th percentiles, Rockset delivers lower data latency than Elasticsearch at the peak throughput. What you can also see is that the data latency is within a tighter bound on Rockset compared to the delta between p50 and p99 on Elasticsearch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QTk1GuC_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/2LLeBIPQqUE6TxJjVief6t/d4919cee8341bf4a8441a6fa58e741f8/Screen_Shot_2023-05-03_at_10.11.53_AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QTk1GuC_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/2LLeBIPQqUE6TxJjVief6t/d4919cee8341bf4a8441a6fa58e741f8/Screen_Shot_2023-05-03_at_10.11.53_AM.png" alt="Graph of the data latency at 50th, 95th and 99th percentiles at the peak throughput rate of Rockset and Elasticsearch. Shows the results of a batch of 500 on 128 vCPU instances. Lower data latency indicates better performance." width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Graph of the data latency at 50th, 95th and 99th percentiles at the peak throughput rate of Rockset and Elasticsearch. Shows the results of a batch of 500 on 128 vCPU instances. Lower data latency indicates better performance.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Rockset was able to achieve up to 2.5x lower latency than Elasticsearch for streaming data ingestion.&lt;/p&gt;

&lt;h2&gt;
  
  
  How did we do it?: Rockset gains due to cloud-native efficiency
&lt;/h2&gt;

&lt;p&gt;There have been open questions as to whether it is possible for a database to achieve both isolation and real-time performance. The de-facto architecture for real-time database systems, including Elasticsearch, is a shared nothing architecture where compute and storage resources are tightly coupled for better performance. With these results, we show that it is possible for a disaggregated&lt;a href="https://rockset.com/blog/introducing-compute-compute-separation/"&gt;cloud architecture&lt;/a&gt; to support search and analytics on high-velocity streaming data.&lt;/p&gt;

&lt;p&gt;One of the tenets of a cloud-native architecture is resource decoupling, made famous by compute-storage separation, which offers better scalability and efficiency. You no longer need to overprovision resources for peak capacity as you can scale up and down on demand. And, you can provision the exact amount of storage and compute needed for your application.&lt;/p&gt;

&lt;p&gt;The knock against decoupled architectures is that they have traded off performance for isolation. In a shared nothing architecture, the tight coupling of resources underpins performance; data ingestion and query processing use the same compute units to ensure that the most recently generated data is available for querying. Storage and compute are also colocated in the same nodes for faster data access and improved query performance.&lt;/p&gt;

&lt;p&gt;While tightly coupled architectures made sense in the past, they are no longer necessary due to advances in cloud architectures. Rockset’s compute-storage and &lt;a href="https://rockset.com/blog/introducing-compute-compute-separation/"&gt;compute-compute separation&lt;/a&gt; for real-time search and analytics lead the way by isolating streaming ingest compute, query compute and hot storage from each other. Rockset is able to ensure queries access the most recent writes by replicating the in-memory state across virtual instances, a cluster of compute and memory resources, making the architecture well-suited to latency sensitive scenarios. Furthermore, Rockset creates an elastic hot storage tier that is a shared resource for multiple applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LuIvNkr0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/6UIYF8VgMpYe8KKQPZExam/bdb09191c552a7959ec25616274aa77f/Screen_Shot_2023-05-03_at_7.25.12_AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LuIvNkr0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/6UIYF8VgMpYe8KKQPZExam/bdb09191c552a7959ec25616274aa77f/Screen_Shot_2023-05-03_at_7.25.12_AM.png" alt="Diagrams of a (a) shared nothing architecture like Elasticsearch and (b) a compute-compute separation architecture introduced by Rockset." width="800" height="449"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Diagrams of a (a) shared nothing architecture like Elasticsearch and (b) a compute-compute separation architecture introduced by Rockset.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With compute-compute separation, Rockset achieves better ingest performance than Elasticsearch because it only has to process incoming data once. In Elasticsearch, which has a &lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-replication.html"&gt;primary-backup model for replication&lt;/a&gt;, every replica needs to expend compute indexing and compacting newly generated writes. With &lt;a href="https://rockset.com/blog/tech-overview-compute-compute-separation/"&gt;compute-compute separation&lt;/a&gt;, only a single virtual instance does the indexing and compaction before transferring the newly written data to other instances for application serving. The efficiency gains from needing to only process incoming writes once is why Rockset recorded up to 4x higher throughput and 2.5x lower end-to-end latency than Elasticsearch on RockBench.&lt;/p&gt;

&lt;h3&gt;
  
  
  In Summary: Rockset achieves up to 4x higher throughput and 2.5x lower latency
&lt;/h3&gt;

&lt;p&gt;In this blog, we have walked through the performance evaluation of Rockset and Elasticsearch for high-velocity data streams and come to the following conclusions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Throughput&lt;/strong&gt; : Rockset supports higher throughput than Elasticsearch, writing incoming streaming data up to 4x faster. We came to this conclusion by measuring the peak throughput, or the rate in which data latency starts monotonically increasing, on different batch sizes and configurations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Latency&lt;/strong&gt; : Rockset consistently delivers lower data latencies than Elasticsearch at the 95th and 99th percentile, making Rockset well suited for latency sensitive application workloads. Rockset provides up to 2.5x lower end-to-end latency than Elasticsearch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cost/Complexity&lt;/strong&gt; : We compared Rockset and Elasticsearch streaming ingest performance on hardware resources, using similar allocations of CPU and memory. We also found that Rockset offers the best value. For a similar price point, you can not only get better performance on Rockset but you can do away with managing clusters, shards, nodes and indexes. This greatly simplifies operations so your team can focus on building production-grade applications.&lt;/p&gt;

&lt;p&gt;We ran this performance benchmark on Rockset’s next generation cloud architecture with compute-compute separation. We were able to prove that even with the isolation of streaming ingestion compute, query compute and storage Rockset was still able to achieve better performance than Elasticsearch.&lt;/p&gt;

&lt;p&gt;You can evaluate Rockset for your own real-time search and analytics workload by starting a &lt;a href="https://rockset.com/create/"&gt;free trial with $300 in credits&lt;/a&gt;. We have built-in connectors to Confluent Cloud, Kafka and Kinesis along with a host of OLTP databases to make it easy for you to get started.&lt;/p&gt;

</description>
      <category>rockset</category>
      <category>elasticsearch</category>
      <category>performance</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Introducing Vector Search on Rockset: How to run semantic search with OpenAI and Rockset</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Tue, 18 Apr 2023 07:00:00 +0000</pubDate>
      <link>https://dev.to/shawn/introducing-vector-search-on-rockset-how-to-run-semantic-search-with-openai-and-rockset-4ijp</link>
      <guid>https://dev.to/shawn/introducing-vector-search-on-rockset-how-to-run-semantic-search-with-openai-and-rockset-4ijp</guid>
      <description>&lt;p&gt;We’re excited to introduce vector search on Rockset to power fast and efficient search experiences, personalization engines, fraud detection systems and more. To highlight these new capabilities, we built a search demo using &lt;a href="https://platform.openai.com/docs/guides/embeddings"&gt;OpenAI&lt;/a&gt; to create embeddings for Amazon product descriptions and Rockset to generate relevant search results. In the demo, you’ll see how Rockset delivers search results in 15 milliseconds over thousands of documents.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use vector search?
&lt;/h2&gt;

&lt;p&gt;Organizations have continued to accumulate large quantities of unstructured data, ranging from text documents to multimedia content to machine and sensor data. Estimates show that unstructured data represents &lt;a href="https://www2.deloitte.com/us/en/insights/topics/analytics/insight-driven-organization.html"&gt;80% of all generated data&lt;/a&gt;, but organizations only leverage a small fraction of it to extract valuable insights, power decision-making and create immersive experiences. Comprehending and understanding how to leverage unstructured data has remained challenging and costly, requiring technical depth and domain expertise. Due to these difficulties, unstructured data has remained largely underutilized.&lt;/p&gt;

&lt;p&gt;With the evolution of machine learning, neural networks and large language models, organizations can easily transform unstructured data into embeddings, commonly represented as vectors. Vector search operates across these vectors to identify patterns and quantify similarities between components of the underlying unstructured data.&lt;/p&gt;

&lt;p&gt;Before vector search, search experiences primarily relied on keyword search, which frequently involved manually tagging data to identify and deliver relevant results. The process of manually tagging documents requires a host of steps like creating taxonomies, understanding search patterns, analyzing input documents, and maintaining custom rule sets. As an example, if we wanted to search for tagged keywords to deliver product results, we would need to manually tag “Fortnite” as a ”survival game” and ”multiplayer game.” We would also need to identify and tag phrases with similarities to “survival game” like “battle royale” and “open-world play” to deliver relevant search results.&lt;/p&gt;

&lt;p&gt;More recently, keyword search has come to rely on term proximity, which relies on tokenization. Tokenization involves breaking down titles, descriptions and documents into individual words and portions of words, and then term proximity functions deliver results based on matches between those individual words and search terms. Although tokenization reduces the burden of manually tagging and managing search criteria, keyword search still lacks the ability to return semantically similar results, especially in the context of natural language which relies on associations between words and phrases.&lt;/p&gt;

&lt;p&gt;With vector search, we can leverage text embeddings to capture semantic associations across words, phrases and sentences to power more robust search experiences. For example, we can use vector search to find games with “space and adventure, open-world play and multiplayer options.” Instead of manually tagging each game with this potential criteria or tokenizing each game description to search for exact results, we would use vector search to automate the process and deliver more relevant results.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do embeddings power vector search?
&lt;/h2&gt;

&lt;p&gt;Embeddings, represented as arrays or vectors of numbers, capture the underlying meaning of unstructured data like text, audio, images and videos in a format more easily understood and manipulated by computational models.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--To9CRnqZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/1g9ijHZkPCwRT1h2tjlhcu/efe1714d0d2338adcba87e6a5f63f266/image__17_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--To9CRnqZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/1g9ijHZkPCwRT1h2tjlhcu/efe1714d0d2338adcba87e6a5f63f266/image__17_.png" alt="Two-dimensional space used to determine the semantic relationship between games using distance functions like cosine, Euclidean distance and dot product" width="800" height="419"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Two-dimensional space used to determine the semantic relationship between games using distance functions like cosine, Euclidean distance and dot product&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As an example, I could use embeddings to understand the relationship between terms like “Fortnite,” “PUBG” and “Battle Royale.” Models derive meaning from these terms by creating embeddings for them, which group together when mapped to a multi-dimensional space. In a two-dimensional space, a model would generate specific coordinates (x, y) for each term, and then we would understand the similarity between these terms by measuring the distances and angles between them.&lt;/p&gt;

&lt;p&gt;In real-world applications, unstructured data can consist of billions of data points and translate into embeddings with thousands of dimensions. Vector search analyzes these types of embeddings to identify terms in close proximity to each other such as “Fortnite” and “PUBG” as well as terms that may be in even closer proximity to each other and synonyms like “PlayerUnknown's Battlegrounds” and the associated acronym “PUBG.”&lt;/p&gt;

&lt;p&gt;Vector search has seen an explosion in popularity due to improvements in accuracy and broadened accessibility to the models used to generate embeddings. Embedding models like &lt;a href="https://cloud.google.com/ai-platform/training/docs/algorithms/bert-start"&gt;BERT&lt;/a&gt; have led to exponential improvements in natural language processing and understanding, generating embeddings with thousands of dimensions. OpenAI’s text embedding model, &lt;a href="https://openai.com/blog/new-and-improved-embedding-model"&gt;text-embedding-ada-002&lt;/a&gt;, generates embeddings with 1,526 dimensions, creating a rich representation of the underlying language.&lt;/p&gt;
&lt;h2&gt;
  
  
  Powering fast and efficient search with Rockset
&lt;/h2&gt;

&lt;p&gt;Given we have embeddings for our unstructured data, we can turn towards vector search to identify similarities across these embeddings. Rockset offers a number of out-of-the-box distance functions, including &lt;a href="https://rockset.com/docs/vector-functions/"&gt;dot product, cosine similarity, and Euclidean distance&lt;/a&gt;, to calculate the similarity between embeddings and search inputs. We can use these similarity scores to support K-Nearest Neighbors (kNN) search on Rockset, which returns the k most similar embeddings to the search input.&lt;/p&gt;

&lt;p&gt;Leveraging the newly released vector operations and distance functions, Rockset now supports vector search capabilities. Rockset extends its real-time search and analytics capabilities to vector search, joining other vector databases like Milvus, Pinecone and Weaviate and alternatives such as &lt;a href="https://rockset.com/comparisons/elasticsearch-vs-rockset/"&gt;Elasticsearch&lt;/a&gt;, in indexing and storing vectors. Under the hood, Rockset utilizes its Converged Index technology, which is optimized for metadata filtering, vector search and keyword search, supporting sub-second search, aggregations and joins at scale.&lt;/p&gt;

&lt;p&gt;Rockset offers a number of benefits along with vector search support to create relevant experiences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-Time Data: Ingest and index incoming data in real-time with support for updates.&lt;/li&gt;
&lt;li&gt;Feature Generation: Transform and aggregate data during the ingest process to generate complex features and reduce data storage volumes. &lt;/li&gt;
&lt;li&gt;Fast Search: Combine vector search and selective metadata filtering to deliver fast, efficient results.&lt;/li&gt;
&lt;li&gt;Hybrid Search Plus Analytics: Join other data with your vector search results to deliver rich and more relevant experiences using SQL.&lt;/li&gt;
&lt;li&gt;Fully-Managed Cloud Service: Run all of these processes on a horizontally scalable, highly available cloud-native database with compute-storage and compute-compute separation for cost-efficient scaling.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Building Product Search Recommendations
&lt;/h2&gt;

&lt;p&gt;Let’s walk through how to run semantic search using OpenAI and Rockset to find relevant products on Amazon.com.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tbGpwUIA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/77lP3f98RUpxz8biKAIOJz/70c1b2fd2ba823fd1e0633bd7812711c/image__18_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tbGpwUIA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/77lP3f98RUpxz8biKAIOJz/70c1b2fd2ba823fd1e0633bd7812711c/image__18_.png" alt="The workflow of semantic search using Amazon product reviews, vector embeddings from OpenAI and nearest neighbor search in Rockset" width="800" height="358"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The workflow of semantic search using Amazon product reviews, vector embeddings from OpenAI and nearest neighbor search in Rockset&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For this demonstration, we used product data that &lt;a href="https://jmcauley.ucsd.edu/data/amazon/"&gt;Amazon&lt;/a&gt; has made available to the public, including product listings and reviews.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p2PoAE-j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/4gMscJXfo2bsq0mPkFWFu2/d1df67fec3960d8f3e45418c0da866e9/image1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p2PoAE-j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/4gMscJXfo2bsq0mPkFWFu2/d1df67fec3960d8f3e45418c0da866e9/image1.png" alt="Sample of the Amazon product reviews dataset" width="800" height="205"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Sample of the Amazon product reviews dataset&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Generate Embeddings
&lt;/h3&gt;

&lt;p&gt;The first stage of this walkthrough involves using &lt;a href="https://platform.openai.com/docs/guides/embeddings"&gt;OpenAI’s text embeddings API&lt;/a&gt; to generate embeddings for Amazon product descriptions. We opted to use OpenAI’s &lt;a href="https://openai.com/blog/new-and-improved-embedding-model"&gt;text-embedding-ada-002&lt;/a&gt; model due to its performance, accessibility and reduced embedding size. Though, we could have used a variety of other models to generate these embeddings, and we considered several models from &lt;a href="https://huggingface.co/sentence-transformers"&gt;HuggingFace&lt;/a&gt;, which users can run locally.&lt;/p&gt;

&lt;p&gt;OpenAI’s model generates an embedding with 1,536 elements. In this walkthrough, we’ll generate and save embeddings for 8,592 product descriptions of video games listed on Amazon. We will also create an embedding for the search query used in the demonstration, “space and adventure, open-world play and multiplayer options.”&lt;/p&gt;

&lt;p&gt;We use the following code to generate the embeddings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import gzip
    import json
    import openai


    # Download the following file from https://cseweb.ucsd.edu/~jmcauley/datasets/amazon_v2/ 
product_data_full = []
for line in gzip.open('./amazon_metadata/meta_Video_Games.json.gz', 'rt', encoding='UTF-8'):
    product_data_full.append(json.loads(line))


    # Remove products without descriptions and embed a subset of the data to save time and money
    product_data = []
    for item in range(12000):
if product_data_full[item]['description'] and product_data_full[item]['price']:
    product_data.append(product_data_full[item])


    # Create embeddings for each product desciption
    for item in product_data:
item['description_embedding'] = openai.Embedding.create(input=item['description'][0], model="text-embedding-ada-002")["data"][0]["embedding"]


    # Create new file with embeddings
    for item in product_data:
jsonString = json.dumps(item)
jsonFile.write(jsonString + '\n')
    jsonFile.close()


    # Generate embedding for future search input
    search_query = 'open-world play, multiplayer options, and support for in-game purchases'
    search_query_embedding = openai.Embedding.create(input=search_query, model="text-embedding-ada-002")["data"][0]["embedding"]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Upload Embeddings to Rockset
&lt;/h3&gt;

&lt;p&gt;In the second step, we’ll upload these embeddings, along with the product data, to Rockset and create a new collection to start running vector search. Here’s how the process works:&lt;/p&gt;

&lt;p&gt;We create a collection in Rockset by uploading the file created earlier with the video game product listings and associated embeddings. Alternatively, we could have easily pulled the data from other storage mechanisms, like Amazon S3 and Snowflake, or streaming services, like Kafka and Amazon Kinesis, leveraging Rockset’s built-in connectors. We then leverage Ingest Transformations to transform the data during the ingest process using SQL. We use Rockset’s new &lt;code&gt;VECTOR_ENFORCE&lt;/code&gt; function to validate the length and elements of incoming arrays, which ensure compatibility between vectors during query execution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9DyUNjdJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/6511jjDxO3KoiNmdsAfBWe/bbca15d373ce677a667dd741fc46f43d/image2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9DyUNjdJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/6511jjDxO3KoiNmdsAfBWe/bbca15d373ce677a667dd741fc46f43d/image2.png" alt="Use of the VECTOR_ENFORCE function as part of an ingest transformation" width="800" height="441"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Use of the &lt;code&gt;VECTOR_ENFORCE&lt;/code&gt; function as part of an ingest transformation&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Run Vector Search on Rockset
&lt;/h3&gt;

&lt;p&gt;Let’s now run vector search on Rockset using the newly released distance functions. &lt;code&gt;COSINE_SIM&lt;/code&gt; takes in the description embeddings field as one argument and the search query embedding as another. Rockset makes all of this possible and intuitive with full-featured SQL.&lt;/p&gt;

&lt;p&gt;For this demonstration, we copied and pasted the search query embedding into the &lt;code&gt;COSINE_SIM&lt;/code&gt; function within the &lt;code&gt;SELECT&lt;/code&gt; statement. Alternatively, we could have generated the embedding in real time by directly calling the OpenAI Text Embedding API and passing the embedding to Rockset as a Query Lambda parameter.&lt;/p&gt;

&lt;p&gt;Due to Rockset’s Converged Index, kNN search queries perform particularly well with selective, metadata filtering. Rockset applies these filters before computing the similarity scores, which optimizes the search process by only calculating scores for relevant documents. For this vector search query, we filter by price and game developer to ensure the results reside within a specified price range and the games are playable on a given device.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U-GJKOWU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/6PsO1wUwbC7erZwQDkuzGR/7af58907fd15d2768b403bc7705e2b42/image3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U-GJKOWU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://images.ctfassets.net/1d31s1aajogl/6PsO1wUwbC7erZwQDkuzGR/7af58907fd15d2768b403bc7705e2b42/image3.png" alt="kNN search on Rockset returns top 5 results in 15MS" width="800" height="493"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;kNN search on Rockset returns top 5 results in 15MS&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Since Rockset filters on brand and price before computing the similarity scores, Rockset returns the top five results on over 8,500 documents in 15 milliseconds on a Large Virtual Instance with 16 vCPUs and 128 GiB of allocated memory. Here are the descriptions for the top three results based on the search input “space and adventure, open-world play and multiplayer options”:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;This role-playing adventure for 1 to 4 players lets you plunge deep into a new world of fantasy and wonder, and experience the dawning of a new series.&lt;/li&gt;
&lt;li&gt;Spaceman just crashed on a strange planet and he needs to find all his spacecraft's parts. The problem? He only has a few days to do it!&lt;/li&gt;
&lt;li&gt;180 MPH slap in the face, anyone? Multiplayer modes for up to four players including Deathmatch, Cop Mode and Tag.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To summarize, Rockset runs semantic search in approximately 15 milliseconds on embeddings generated by OpenAI, using a combination of vector search with metadata filtering for faster, more relevant results.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does this mean for search?
&lt;/h2&gt;

&lt;p&gt;We walked through an example of how to use vector search to power semantic search and there are many other examples where fast, relevant search can be useful:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Personalization &amp;amp; Recommendation Engines&lt;/strong&gt; : Leverage vector search in your e-commerce websites and consumer applications to determine interests based on activities like past purchases and page views. Vector search algorithms can help generate product recommendations and deliver personalized experiences by identifying similarities between users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anomaly Detection&lt;/strong&gt; : Incorporate vector search to identify anomalous transactions based on their similarities (and differences!) to past, legitimate transactions. Create embeddings based on attributes such as transaction amount, location, time, and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Predictive Maintenance&lt;/strong&gt; : Deploy vector search to help analyze factors such as engine temperature, oil pressure, and brake wear to determine the relative health of trucks in a fleet. By comparing readings to reference readings from healthy trucks, vector search can identify potential issues such as a malfunctioning engine or worn-out brakes.&lt;/p&gt;

&lt;p&gt;In the upcoming years, we expect the use of unstructured data to skyrocket as large language models become easily accessible and the cost of generating embeddings continues to decline. Rockset will help accelerate the convergence of real-time machine learning with real-time analytics by easing the adoption of vector search with a fully-managed, cloud-native service.&lt;/p&gt;

&lt;p&gt;Search has become easier than ever as you no longer need to build complex and hard-to-maintain rules-based algorithms or manually configure text tokenizers or analyzers. We see endless possibilities for vector search: explore Rockset for your use case by starting a &lt;a href="https://rockset.com/create/"&gt;free trial today&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Author: John Solitario, Product Manager&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>nlp</category>
      <category>database</category>
    </item>
    <item>
      <title>Rockset Architecture Whiteboard Session With CTO Dhruba Borthakur</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Tue, 14 Jun 2022 13:00:00 +0000</pubDate>
      <link>https://dev.to/rocksetcloud/rockset-architecture-whiteboard-session-with-cto-dhruba-borthakur-5eh5</link>
      <guid>https://dev.to/rocksetcloud/rockset-architecture-whiteboard-session-with-cto-dhruba-borthakur-5eh5</guid>
      <description>&lt;p&gt;In this 30 minute video overview, CTO and Rockset Co-founder Dhruba Borthakur discusses &lt;a href="https://rockset.com/blog/aggregator-leaf-tailer-an-architecture-for-live-analytics-on-event-streams/"&gt;Rockset's ALT architecture&lt;/a&gt;, how data is &lt;a href="https://rockset.com/whitepapers/rockset-concepts-designs-and-architecture/"&gt;ingested, stored and queried in Rockset&lt;/a&gt;, and why Rockset is simple to use, incredibly fast and capable of the highly efficient execution of complex distributed queries across diverse data sets.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EJ5rQc9j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/19HNG5PhXbTR3ewJr5kIIY/1164adf81777780cd98bfd75695f0c17/dhruba-whiteboard.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EJ5rQc9j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/19HNG5PhXbTR3ewJr5kIIY/1164adf81777780cd98bfd75695f0c17/dhruba-whiteboard.jpg" alt="dhruba-whiteboard" width="880" height="575"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We'll be doing more videos like this in the future, so sign up for &lt;a href="https://rockset.com/blog"&gt;notices from our blog&lt;/a&gt; and &lt;a href="https://community.rockset.com"&gt;join our community&lt;/a&gt; so you don't miss them.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/msW8nh5TTwQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn More about Rockset Architecture
&lt;/h2&gt;

&lt;p&gt;You can find more information about Rockset's architecture and functionality in the following resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://rockset.com/blog/aggregator-leaf-tailer-an-architecture-for-live-analytics-on-event-streams/"&gt;Aggregator Leaf Tailer: An Alternative to Lambda Architecture for Real-Time Analytics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://rockset.com/whitepapers/rockset-concepts-designs-and-architecture/"&gt;Rockset Concepts, Design &amp;amp; Architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://rockset.com/understanding-rockset-guide.pdf"&gt;Understanding Rockset – How It Works&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://rockset.com/docs/"&gt;Rockset Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hG-9N99F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/7eTPLKLzpYTZSju3EVHlsG/e78e7d75ebbb73c8cdaa3b2b47749173/leaf-tailer.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hG-9N99F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/7eTPLKLzpYTZSju3EVHlsG/e78e7d75ebbb73c8cdaa3b2b47749173/leaf-tailer.png" alt="Diagram of Rockset ALT architecture" width="880" height="495"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Diagram of Rockset ALT architecture&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  About Dhruba Borthakur
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/dhruba/"&gt;Dhruba Borthakur&lt;/a&gt; is CTO and co-founder of Rockset, responsible for the company's technical direction. He was an engineer on the database team at Facebook, where he was the founding engineer of the &lt;a href="http://rocksdb.org/"&gt;RocksDB&lt;/a&gt; data store. Earlier at Yahoo, he was one of the founding engineers of the &lt;a href="https://hadoop.apache.org/"&gt;Hadoop Distributed File System&lt;/a&gt;. He was also a contributor to the open source &lt;a href="https://hbase.apache.org/"&gt;Apache HBase&lt;/a&gt; project. Dhruba previously held various roles at Veritas Software, founded an e-commerce startup, Oreceipt.com, and contributed to &lt;a href="https://en.wikipedia.org/wiki/Andrew_File_System"&gt;Andrew File System (AFS)&lt;/a&gt; at IBM-Transarc Labs. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XfOMIRiq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/1Rst8GArUnagjFj5qvafzo/c51d058fb652da85ecd2bf2711d9f035/dhruba-from-6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XfOMIRiq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/1Rst8GArUnagjFj5qvafzo/c51d058fb652da85ecd2bf2711d9f035/dhruba-from-6.jpg" alt="dhruba-from-6" width="880" height="613"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  About Rockset
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://rockset.com"&gt;Rockset&lt;/a&gt; is a &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; database that enables queries on massive, semi-structured data without operational burden. Rockset is serverless and fully managed. It offloads the work of managing configuration, cluster provisioning, denormalization and shard/index management. Rockset is also SOC 2 Type II compliant and offers encryption at rest and in flight, securing and protecting any sensitive data. Most teams can ingest data into Rockset and start executing queries in about 15 minutes, depending on the amount of data ingested.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Rockset&lt;/strong&gt; is the leading &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; platform built for the cloud, delivering fast analytics on real-time data with surprising efficiency. Learn more at &lt;a href="https://rockset.com/"&gt;rockset.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>rockset</category>
      <category>database</category>
      <category>realtimeanalytics</category>
      <category>nosql</category>
    </item>
    <item>
      <title>MongoDB vs DynamoDB Head-to-Head: Which Should You Choose?</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Tue, 07 Jun 2022 15:00:00 +0000</pubDate>
      <link>https://dev.to/rocksetcloud/mongodb-vs-dynamodb-head-to-head-which-should-you-choose-5d2n</link>
      <guid>https://dev.to/rocksetcloud/mongodb-vs-dynamodb-head-to-head-which-should-you-choose-5d2n</guid>
      <description>&lt;p&gt;Databases are a key architectural component of many applications and services.&lt;/p&gt;

&lt;p&gt;Traditionally, organizations have chosen relational databases like SQL Server, &lt;a href="https://rockset.com/press/rockset-enables-cost-effective-real-time-analytics-for-oracle-users/"&gt;Oracle&lt;/a&gt;, &lt;a href="https://rockset.com/solutions/mysql"&gt;MySQL&lt;/a&gt; and &lt;a href="https://rockset.com/solutions/postgresql"&gt;Postgres&lt;/a&gt;. Relational databases use tables and structured languages to store data. They usually have a fixed schema, strict data types and formally-defined relationships between tables using foreign keys. They’re reliable, fast and support checks and constraints that help enforce data integrity.&lt;/p&gt;

&lt;p&gt;They aren’t perfect, though. As companies become increasingly digital, they often begin generating massive amounts of data, and they need a place to store it. Relational databases scale up well, but can be painful to scale &lt;em&gt;out&lt;/em&gt; when a company has more data than a single database server can manage.&lt;/p&gt;

&lt;p&gt;On the other hand, non-relational databases (commonly referred to as NoSQL databases) are flexible databases for big data and real-time web applications. These databases were born out of necessity for storing large amounts of unstructured data. NoSQL databases don't always offer the same data integrity guarantees as a relational database, but they're much easier to scale out across multiple servers.&lt;/p&gt;

&lt;p&gt;NoSQL databases have become so popular that big companies rely on them to store hundreds of terabytes of data and run millions of queries per second. So why have NoSQL databases become so popular compared to traditional, relational databases?&lt;/p&gt;

&lt;p&gt;For one, NoSQL databases can accept any type of data: structured, unstructured or semi-structured. This flexibility makes them the go-to database for many use cases. Secondly, NoSQL is schemaless, so database items can have completely different structures from one another. And as mentioned, due to their architectures, NoSQL databases are easier to scale horizontally than relational databases.&lt;/p&gt;

&lt;p&gt;There are many NoSQL databases available in the market. Two popular options are &lt;a href="https://rockset.com/solutions/mongodb/"&gt;MongoDB&lt;/a&gt; and &lt;a href="https://rockset.com/sql-on-dynamodb/"&gt;Amazon DynamoDB&lt;/a&gt;, and architects often find themselves choosing between the two. In this article, we’ll compare MongoDB and Amazon DynamoDB to each other and highlight their significant differences. We’ll include their pros and cons, differences in data types, and discuss factors like cost, reliability, performance and security.&lt;/p&gt;

&lt;p&gt;Before comparing MongoDB to DynamoDB, let’s take an in-depth look at each solution to understand what they are, their characteristics and their advantages and disadvantages.&lt;/p&gt;

&lt;h2&gt;
  
  
  In This Corner, MongoDB
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.mongodb.com/"&gt;MongoDB&lt;/a&gt; is a NoSQL, document-oriented general purpose database management system. It is optimized for low latency, high throughput, and high availability. It also supports a JavaScript-based query language to run commands and retrieve data, with official client drivers available for over a dozen programming languages. It’s a cross-platform, open-source non-relational database that stores data as collections of documents.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YwNhmYtG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/5whylSF1tMy1OAu1Bwbav1/64cca2b74178d2ede624ec1e30e8ec88/MongoDB_Logo_FullColorBlack_RGB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YwNhmYtG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/5whylSF1tMy1OAu1Bwbav1/64cca2b74178d2ede624ec1e30e8ec88/MongoDB_Logo_FullColorBlack_RGB.png" alt="MongoDB Logo FullColorBlack RGB" width="880" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;MongoDB uses BSON internally to store documents which is a binary representation of JSON that fully supports all of the features of JSON with support for additional data types, more efficient compression, and easier parsability. While MongoDB collections can have a schema against which the database validates new documents, schema validation is optional.&lt;/p&gt;

&lt;h3&gt;
  
  
  MongoDB’s Characteristics
&lt;/h3&gt;

&lt;p&gt;MongoDB is a general-purpose database. It can serve various loads and multiple purposes within an &lt;a href="https://rockset.com/what-is-a-data-application/"&gt;application&lt;/a&gt;. It also has a flexible schema design, meaning there’s no set schema to define how to store data, and it scales both vertically and horizontally. MongoDB takes into account security features such as authentication and authorization. It also has a document model that maps to objects in application code, making it easy to work with data.&lt;/p&gt;

&lt;h4&gt;
  
  
  MongoDB’s Pros
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility:&lt;/strong&gt; MongoDB has flexible database schemas. You can insert information into the database without worrying about matching criteria or data types. MongoDB supports more native data types than DynamoDB, and it lets you nest documents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Systems Design:&lt;/strong&gt; Beyond accommodating large volumes of rapidly changing structured, semi-structured and unstructured data, MongoDB enables developers to add to the schema as their needs change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Model:&lt;/strong&gt; Compared to DynamoDB, MongoDB supports regular JSON and advanced BSON data models such as int, long, date, timestamp, geospatial, floating-point and Decimal128.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Runs Anywhere:&lt;/strong&gt; This solution can run anywhere, so users future-proof their work without fearing vendor lock-in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost:&lt;/strong&gt; MongoDB has a free, open-source version if you are cost conscious. They’ve also recently introduced a &lt;a href="https://www.mongodb.com/use-cases/serverless"&gt;pay-as-you-go, serverless pricing&lt;/a&gt; option for MongoDB Atlas, their managed cloud offering.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  MongoDB’s Cons
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Memory Use:&lt;/strong&gt; MongoDB needs to keep its working set in RAM to achieve acceptable performance. This reliance on RAM makes MongoDB too expensive for many use cases. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Duplication:&lt;/strong&gt; Duplication happens because, in MongoDB, users tend to use nested documents instead of normalized tables like in a relational database. In some cases this may be due to denormalization that needs to occur because MongoDB does not support high performance JOINs, and instead uses a &lt;em&gt;data that belongs together is stored together&lt;/em&gt; philosophy to avoid the use of JOINS entirely. This limitation can cause data sizes, and the related costs, to climb.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Indexing:&lt;/strong&gt; MongoDB supports simple indexes and complex compound indexes containing multiple document properties. As with most databases, poorly designed or missing indexes can slow reads and writes, as the index must update every time someone inserts a new document in a collection.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  And, in This Corner, DynamoDB
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://aws.amazon.com/dynamodb/"&gt;Amazon DynamoDB&lt;/a&gt; is a fast, flexible, NoSQL database. It’s suitable for all applications that need consistent latency at any scale. It’s a fully managed NoSQL database that’s ideal for document and key-value models. Amazon developed DynamoDB as a managed database for applications requiring similar, simple query patterns.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D0PHvbdD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/14maXj1lPrh2qZVKeA0Qt1/1f1ff99a8e7aea841da372ca719959fb/dynamodb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D0PHvbdD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/14maXj1lPrh2qZVKeA0Qt1/1f1ff99a8e7aea841da372ca719959fb/dynamodb.png" alt="dynamodb" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;DynamoDB can scale on-demand to support virtually unlimited read and write operations with response time under single-digit milliseconds. It’s perfect for mobile, web, gaming and advertising technology.&lt;/p&gt;

&lt;h3&gt;
  
  
  DynamoDB’s Characteristics
&lt;/h3&gt;

&lt;p&gt;DynamoDB is serverless and scales horizontally to support tables of any size, making it good for large-scale performance. Plus, query performance doesn’t degrade with database size when querying by key. It also has a flexible schema that enables you to quickly adapt tables as your needs change without restructuring the table schema (as required in relational databases).&lt;/p&gt;

&lt;p&gt;DynamoDB also offers global tables, albeit at an extra cost. These tables replicate your data across AWS Regions, making it easy for your app to locally access data in the selected regions. DynamoDB also continuously backs up your data to prevent data loss. It encrypts your data for improved security, and is ideally suited for enterprise applications that have strict security requirements.&lt;/p&gt;

&lt;h4&gt;
  
  
  DynamoDB’s Pros
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Customizable:&lt;/strong&gt; The DynamoDB database can be modified according to your app’s priorities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast:&lt;/strong&gt; DynamoDB delivers excellent performance, no matter how many records you store or how often you query it by key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; DynamoDB scales seamlessly, regardless of the traffic levels.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pricing:&lt;/strong&gt; DynamoDB uses a pay-as-you-go, throughput-based pricing technique where different inputs may affect prices. This can help to optimize your costs as they will fluctuate with your workload, but may also cause your pricing to be unpredictable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  DynamoDB’s Cons
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Limited Query Language:&lt;/strong&gt; DynamoDB has a limited query language compared to MongoDB. This is because DynamoDB is a key-value store and not a full document database. Every DynamoDB record has two keys: a partition key and a sort key. Every query must provide one partition key, and can optionally specify a single value or a range for the sort key. That’s it. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limited Indexing:&lt;/strong&gt; Compared to MongoDB, where indexing your data comes at no extra cost, DynamoDB indexes are limited and complex. Amazon sizes and bills the indexes separately from data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pricing:&lt;/strong&gt; DynamoDB uses a pay-as-you-go, throughput-based pricing technique where different inputs may affect prices. This can help to optimize your costs as they will fluctuate with your workload, but may also cause your pricing to be unpredictable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Head-to-Head Table of MongoDB vs DynamoDB
&lt;/h2&gt;

&lt;p&gt;Both Amazon DynamoDB and MongoDB are widely used, highly scalable and cloud-compatible NoSQL databases. Despite these similarities, they have some key differences. The table below explores these further:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;MongoDB&lt;/th&gt;
&lt;th&gt;DynamoDB&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Source&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;MongoDB is open-source and can be deployed anywhere in most clouds and/or on premises.&lt;/td&gt;
&lt;td&gt;DynamoDB is from the AWS ecosystem and can only be used within AWS.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Management&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;MongoDB can either be self-managed or fully managed with the MongoDB Atlas database as a service.&lt;/td&gt;
&lt;td&gt;DynamoDB is a fully managed solution. Amazon handles all server updates, patch updates, and hardware provisioning.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Security&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Developers need to spend extra time upfront reconfiguring security on MongoDB, especially when self-managed. This is because it runs with defaults permitting unrestricted and direct access to data without authentication. MongoDB Atlas requires setup of authentication and network access via IP access controls or VPC peering.&lt;/td&gt;
&lt;td&gt;Security for DynamoDB starts out restrictive and incorporates with AWS IAM Policy infrastructure.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Database structure&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;MongoDB’s database structure is made of JSON-like documents comprising collections, keys, values, and documents. Documents can contain nested documents.&lt;/td&gt;
&lt;td&gt;DynamoDB’s database structure supports either blobs or documents as values.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Index use&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;MongoDB supports up to 64 mutable indexes per collection, allowing the document’s structure to change dynamically.&lt;/td&gt;
&lt;td&gt;DynamoDB supports up to 20 mutable global indexes per table which are not compatible with underlying data, and up to 5 local indexes which cannot be modified after table creation.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Programming language&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;MongoDB is written in C++ and supports programming languages like C, C++, Go, Java, JavaScript, PHP, Perl, Ruby, Python, and more.&lt;/td&gt;
&lt;td&gt;DynamoDB supports programming languages like Java, JavaScript, Node.js, .NET, PHP, and more.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Data type and size restriction&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;MongoDB supports various data types, and allows document sizes of up to 16MB.&lt;/td&gt;
&lt;td&gt;DynamoDB has limited support for data types, and allows item sizes of up to 400 KB.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Industry use&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Companies use MongoDB for mobile apps and content management systems (CMSs). MongoDB is also excellent for scalability and caching.&lt;/td&gt;
&lt;td&gt;The gaming and Internet of things (IoT) industries widely use DynamoDB.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cost&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;MongoDB uses a fixed pricing model where you pay for provisioned resources ahead of time. Pricing is based on RAM, I/O, and storage for MongoDB Atlas, plus server and sysadmin time if you are hosting MongoDB yourself. Costs are consistent, but may not be optimal for variable workloads.&lt;/td&gt;
&lt;td&gt;DynamoDB uses a variable pricing model where you pay for what you use, which is based on a throughput model with additional charges for features like backup and restore, on-demand capacity, streams, change data capture (CDC) and others. This may cause your costs to be less predictable.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Querying&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;MongoDB has a rich query language. You can apply it in various ways: single keys, ranges, graph transversals, joins, and more.&lt;/td&gt;
&lt;td&gt;DynamoDB’s querying is only available in local secondary indexes (LSI) and global secondary indexes (GSI).&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Which Database Should I Choose, MongoDB or DynamoDB?
&lt;/h2&gt;

&lt;p&gt;DynamoDB and MongoDB are highly successful modern alternatives for traditional database systems, such as MySQL, PostgreSQL and others. When selecting your database, you need to consider factors such as scale, user requirements, deployment method, storage requirements and functionality.&lt;/p&gt;

&lt;p&gt;If you’re looking for an AWS-native solution with MongoDB-like capabilities, you can also consider Amazon DocumentDB. While DocumentDB is not based on the MongoDB server, its abilities are close to MongoDB, and is compatible with the &lt;a href="https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html"&gt;MongoDB 3.6 and 4.0 APIs&lt;/a&gt;. You can even use DocumentDB as a drop-in replacement for MongoDB as it is MongoDB compatible.&lt;/p&gt;

&lt;p&gt;MongoDB and DynamoDB are both solid NoSQL databases that meet and solve various user needs. You need to carefully consider whether or not a database fully suits your use case. Each database has unique advantages, so factor in your long-term cloud strategy and an application’s specific needs when deciding which NoSQL database to select.&lt;/p&gt;

&lt;p&gt;Regardless of which NoSQL database you use, pairing it with a &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; database is a common pattern, as neither MongoDB or DynamoDB is primarily an analytical database. If you're building user-facing &lt;a href="https://rockset.com/what-is-a-data-application/"&gt;data applications&lt;/a&gt; using your data stored in MongoDB or DynamoDB, consider &lt;a href="https://rockset.com"&gt;Rockset&lt;/a&gt;, which enables real-time SQL analytics on your &lt;a href="https://rockset.com/solutions/mongodb/"&gt;MongoDB&lt;/a&gt; or &lt;a href="https://rockset.com/sql-on-dynamodb/"&gt;DynamoDB&lt;/a&gt; NoSQL database.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Rockset&lt;/strong&gt; is the leading &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; platform built for the cloud, delivering fast analytics on real-time data with surprising efficiency. Learn more at &lt;a href="https://rockset.com/"&gt;rockset.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>dynamodb</category>
      <category>nosql</category>
      <category>database</category>
    </item>
    <item>
      <title>CDC on DynamoDB</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Tue, 10 May 2022 13:00:00 +0000</pubDate>
      <link>https://dev.to/rocksetcloud/cdc-on-dynamodb-4idk</link>
      <guid>https://dev.to/rocksetcloud/cdc-on-dynamodb-4idk</guid>
      <description>&lt;p&gt;DynamoDB is a popular NoSQL database available in AWS. It is a managed service with minimal setup and pay-as-you-go costing. Developers can quickly create databases that store complex objects with flexible schemas that can mutate over time. &lt;a href="https://rockset.com/sql-on-dynamodb/"&gt;DynamoDB&lt;/a&gt; is resilient and scalable due to the use of sharding techniques. This seamless, horizontal scaling is a huge advantage that allows developers to move from a proof of concept into a productionized service very quickly.&lt;/p&gt;

&lt;p&gt;However, DynamoDB, like many other NoSQL databases, is great for scalable data storage and single row retrieval but leaves a lot to be desired when it comes to analytics. With SQL databases, analysts can quickly join, group and search across historical data sets. With NoSQL, the language for performing these types of queries is often more cumbersome, proprietary, and joining data is either not possible or not recommended due to performance constraints.&lt;/p&gt;

&lt;p&gt;To overcome this, &lt;a href="https://rockset.com/blog/change-data-capture-what-it-is-and-how-to-use-it/"&gt;Change Data Capture (CDC)&lt;/a&gt; techniques are often used to copy changes from the NoSQL database into an analytics database where analysts can perform more computationally heavy tasks across larger datasets. In this post, we’ll look at how CDC works with DynamoDB and its potential use cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Change Data Capture Works on DynamoDB
&lt;/h2&gt;

&lt;p&gt;We have previously discussed the &lt;a href="https://rockset.com/blog/change-data-capture-what-it-is-and-how-to-use-it/"&gt;many different CDC techniques&lt;/a&gt; available. DynamoDB uses a push-type model where changes are pushed to a downstream entity such as a queue or a direct consumer. DynamoDB pushes events about any changes to a DynamoDB stream that can be consumed by targets downstream.&lt;/p&gt;

&lt;p&gt;Usually, push-based CDC patterns are more complex as they often require another service to act as the middleman between the producer and consumer of the changes. However, DynamoDB streams are natively supported within DynamoDB and can be simply configured and enabled with a touch of a button. This is because they are also a managed service within &lt;a href="https://rockset.com/comparisons/rockset-vs-data-warehouse"&gt;AWS&lt;/a&gt;. CDC on DynamoDB is easy because you only need to configure a consumer and an alternative data store.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Cases for CDC on DynamoDB
&lt;/h2&gt;

&lt;p&gt;Let's take a look at some use cases for why you would need a CDC solution in the first place.&lt;/p&gt;

&lt;h3&gt;
  
  
  Archiving Historical Data
&lt;/h3&gt;

&lt;p&gt;Due to its scalability and schemaless nature, DynamoDB is often used to store time-series data such as &lt;a href="https://rockset.com/solutions/logistics/"&gt;IoT data&lt;/a&gt; or weblogs. The schema of the data in these sources can change depending on what is being logged at any point in time and they often write data at variable speeds depending on current use. This makes DynamoDB a great use case for storing this data as it can handle the flexible schemas and can also scale up and down on-demand based on the throughput of data.&lt;/p&gt;

&lt;p&gt;However, the utility of this data diminishes over time as the data becomes old and out of date. With pay-as-you-go pricing, the more data stored in DynamoDB the more it costs. This means you only want to use DynamoDB as a hot data store for frequently used data sets. Old and stale data should be removed to save cost and also help with efficiency. Often, companies don't want to simply delete this data and instead want to move it elsewhere for archival.&lt;/p&gt;

&lt;p&gt;Setting up the CDC DynamoDB stream is a great use case to solve this. Changes can be captured and sent to the data stream so it can be archived in S3 or another data store and a &lt;a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html"&gt;data retention policy can be set up&lt;/a&gt; on the data in DynamoDB to automatically delete it after a certain period of time. This reduces storage costs in DynamoDB as the cold data is offloaded to a cheaper storage platform.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-Time Analytics on DynamoDB
&lt;/h3&gt;

&lt;p&gt;As stated previously, DynamoDB is great at retrieving data fast but isn't designed for large-scale data retrieval or complex queries. For example, let's say you have a game that stores user events for each interaction and these events are being written to DynamoDB. Depending on the number of users playing at any time, you need to quickly scale your storage solution to deal with the current throughput making DynamoDB a great choice.&lt;/p&gt;

&lt;p&gt;However, you now want to &lt;a href="https://rockset.com/blog/scaling-real-time-gaming-leaderboards-with-dynamodb-and-rockset/"&gt;build a leaderboard&lt;/a&gt; that provides statistics for each of these interactions and shows the top ten players based on a particular metric. This &lt;a href="https://rockset.com/webinars/gaming-leaderboards-talk/"&gt;leaderboard would need to update in real time&lt;/a&gt; as new events are captured. DynamoDB does not natively support real-time aggregations of data so this is another use case for using CDC out to an analytics platform.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G330noB---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/1jCwTgtUhnZrDbcpWN6oEu/789b291b2b618cde801d91b7d939f165/cdc-on-dynamodb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G330noB---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/1jCwTgtUhnZrDbcpWN6oEu/789b291b2b618cde801d91b7d939f165/cdc-on-dynamodb.png" alt="cdc-on-dynamodb" width="880" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rockset, a &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; database, is an ideal fit for this scenario. It has a &lt;a href="https://rockset.com/blog/20x-faster-ingestion-with-rocksets-new-dynamodb-connector/"&gt;built-in connector for DynamoDB&lt;/a&gt; that automatically configures the DynamoDB stream so changes are ingested into Rockset in near real time. The data is automatically indexed in Rockset for fast analytical queries and SQL querying to perform aggregations and calculations across the data.&lt;/p&gt;

&lt;p&gt;Millisecond latency queries can be set up to constantly retrieve the latest version of the leaderboard as new data is ingested. Like DynamoDB, Rockset is a fully serverless solution providing the same scaling and hands-free infrastructure benefits.&lt;/p&gt;

&lt;h3&gt;
  
  
  Joining Datasets Together
&lt;/h3&gt;

&lt;p&gt;Similar to its lack of analytics capabilities, DynamoDB doesn’t support the joining of tables in queries. NoSQL databases in general tend to lack this capability as data is stored in more complex structures instead of in flat, relational schemas. However, there are times when joining data together for analytics is critical.&lt;/p&gt;

&lt;p&gt;Going back to our real-time gaming leaderboard, rather than just using data from one DynamoDB table, what if we wanted our leaderboard to contain other metadata about a user that comes from a different data source altogether? What if we also wanted to show past performance? These use cases would require queries with table joins.&lt;/p&gt;

&lt;p&gt;Again, we could continue to use Rockset in this scenario. &lt;a href="https://rockset.com/docs/ingest-your-own-data/"&gt;Rockset has multiple connectors available for databases&lt;/a&gt; like &lt;a href="https://rockset.com/solutions/mysql"&gt;MySQL&lt;/a&gt;, &lt;a href="https://rockset.com/solutions/postgresql"&gt;Postgres&lt;/a&gt;, &lt;a href="https://rockset.com/solutions/mongodb/"&gt;MongoDB&lt;/a&gt;, flat files and many more. We could set up connectors to update the data in real time and then amend our leaderboard SQL query to now join this data and a subquery of past performance to be shown alongside the current leaderboard scores.&lt;/p&gt;

&lt;h3&gt;
  
  
  Search
&lt;/h3&gt;

&lt;p&gt;Another use case for implementing CDC with DynamoDB streams is search. As we know, DynamoDB is great for fast document lookups using indexes but searching and filtering large data sets is typically slow.&lt;/p&gt;

&lt;p&gt;For searching documents with lots of text, AWS offers CloudSearch, a managed search solution that provides flexible indexing to provide fast search results with custom, weighted ordering. It is possible to sync DynamoDB data into Cloudsearch however, currently, the solution does not make use of DymanoDB Streams and &lt;a href="https://docs.aws.amazon.com/cloudsearch/latest/developerguide/searching-dynamodb-data.html"&gt;requires a manual technical solution to sync the data&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;On the other hand, with Rockset you can use its DynamoDB connector to sync data in near real time into Rockset where for a simple search you can use standard SQL &lt;code&gt;where&lt;/code&gt; clauses. For more complex search, &lt;a href="https://rockset.com/docs/text-search-functions/"&gt;Rockset offers search functions&lt;/a&gt; to look for specific terms, boost certain results and also perform proximity matching. This could be a viable alternative to AWS CloudSearch if you aren’t searching through large amounts of text and is also easier to set up due to it using the DynamoDB streams CDC method. The data also becomes searchable in near real time and is indexed automatically. CloudSearch &lt;a href="https://docs.aws.amazon.com/cloudsearch/latest/developerguide/limits.html"&gt;has limitations on data size and upload frequency&lt;/a&gt; in a 24-hour period.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Flexible and Future-Proofed Solution
&lt;/h2&gt;

&lt;p&gt;It is clear that AWS DynamoDB is a great NoSQL database offering. It is fully managed, easily scalable and cost-effective for developers building solutions that require fast writes and fast single row lookups. For use cases outside of this, you will probably want to implement a CDC solution to move the data into an alternative data store that is more suited to the use case. DynamoDB makes this easy with the use of DynamoDB streams.&lt;/p&gt;

&lt;p&gt;Rockset takes advantage of DynamoDB streams by providing a built-in connector that can capture changes in seconds. As I have described, many of the common use cases for implementing a CDC solution for DynamoDB can be covered by Rockset. Being a fully managed service, it removes infrastructure burdens from developers. Whether your use case is real-time analytics, joining data and/or search, Rockset can provide all three on the same datasets, meaning you can solve more use cases with fewer architectural components.&lt;/p&gt;

&lt;p&gt;This makes Rockset a flexible and future-proofed solution for many real-time analytic use cases on data stored in DynamoDB.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Rockset&lt;/strong&gt; is the leading &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;Real-time Analytics&lt;/a&gt; Platform Built for the Cloud, delivering fast analytics on real-time data with surprising efficiency. Learn more at &lt;a href="https://rockset.com/"&gt;rockset.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>cdc</category>
      <category>dynamodb</category>
      <category>nosql</category>
      <category>database</category>
    </item>
    <item>
      <title>How Rockset Handles Data Deduplication</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Tue, 03 May 2022 13:00:00 +0000</pubDate>
      <link>https://dev.to/rocksetcloud/how-rockset-handles-data-deduplication-4f1k</link>
      <guid>https://dev.to/rocksetcloud/how-rockset-handles-data-deduplication-4f1k</guid>
      <description>&lt;p&gt;by Tyler Denton, Sales Engineer, Rockset&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are two major problems with distributed data systems. The second is out-of-order messages, the first is duplicate messages, the third is off-by-one errors, and the first is duplicate messages.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This joke inspired Rockset to confront the data duplication issue through a process we call &lt;em&gt;deduplication&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;As data systems become more complex and the number of systems in a stack increases, data deduplication becomes more challenging. That's because duplication can occur in a multitude of ways. This blog post discusses data duplication, how it plagues teams adopting &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt;, and the deduplication solutions Rockset provides to resolve the duplication issue. Whenever another distributed data system is added to the stack, organizations become weary of the operational &lt;em&gt;tax&lt;/em&gt; on their engineering team.&lt;/p&gt;

&lt;p&gt;Rockset addresses the issue of data duplication in a simple way, and helps to free teams of the complexities of deduplication, which includes untangling where duplication is occurring, setting up and managing &lt;a href="https://rockset.com/blog/Reverse-ETL-Integration-Census-Hightouch-Omnata/"&gt;extract transform load (ETL)&lt;/a&gt; jobs, and attempting to solve duplication at a query time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Duplication Problem
&lt;/h2&gt;

&lt;p&gt;In distributed systems, messages are passed back and forth between many workers, and it’s common for messages to be generated two or more times. A system may create a duplicate message because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A confirmation was not sent.&lt;/li&gt;
&lt;li&gt;The message was replicated before it was sent. &lt;/li&gt;
&lt;li&gt;The message confirmation comes after a timeout.&lt;/li&gt;
&lt;li&gt;Messages are delivered out of order and must be resent. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The message can be received multiple times with the same information by the time it arrives at a database management system. Therefore, your system must ensure that duplicate records aren’t created. Duplicate records can be costly and take up memory unnecessarily. These duplicated messages must be consolidated into a single message.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AlgVM8Ui--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/6i7sMqpNVBK3V96Av5xbup/a8ae8d5a140b5cd7c98555fb02e7512a/Deduplication_blog-diagram.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AlgVM8Ui--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/6i7sMqpNVBK3V96Av5xbup/a8ae8d5a140b5cd7c98555fb02e7512a/Deduplication_blog-diagram.jpg" alt="Deduplication blog-diagram" width="880" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deduplication Solutions
&lt;/h2&gt;

&lt;p&gt;Before Rockset, there were three general deduplication methods:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Stop duplication before it happens.&lt;/li&gt;
&lt;li&gt;Stop duplication during ETL jobs.&lt;/li&gt;
&lt;li&gt;Stop duplication at query time.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Deduplication History
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://rockset.com/sql-on-kafka/"&gt;Kafka&lt;/a&gt; was one of the first systems to create a solution for duplication. Kafka guarantees that a message is delivered once and only once. However, if the problem occurs upstream from Kafka, their system will see these messages as non-duplicates and deliver the duplicate messages with different timestamps. Therefore, &lt;em&gt;exactly once&lt;/em&gt; semantics do not always solve duplication issues and can negatively impact downstream workloads.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stop Duplication Before it Happens
&lt;/h3&gt;

&lt;p&gt;Some platforms attempt to stop duplication before it happens. This seems ideal, but this method requires difficult and costly work to identify the location and causes of the duplication.&lt;/p&gt;

&lt;p&gt;Duplication is commonly caused by any of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A switch or router.&lt;/li&gt;
&lt;li&gt;A failing consumer or worker.&lt;/li&gt;
&lt;li&gt;A problem with gRPC connections.&lt;/li&gt;
&lt;li&gt;Too much traffic.&lt;/li&gt;
&lt;li&gt;A window size that is too small for packets. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Keep in mind this is not an exhaustive list.&lt;/p&gt;

&lt;p&gt;This deduplication approach requires in-depth knowledge of the system network, as well as the hardware and framework(s). It is very rare, even for a full-stack developer, to understand the intricacies of all the layers of the OSI model and its implementation at a company. The data storage, access to data pipelines, data transformation, and application internals in an organization of any substantial size are all beyond the scope of a single individual. As a result, there are specialized job titles in organizations. The ability to troubleshoot and identify all locations for duplicated messages requires in-depth knowledge that is simply unreasonable for an individual to have, or even a cross-functional team. Although the cost and expertise requirements are very high, this approach offers the greatest reward.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oRgJeyCT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/4bj8dCUSqBG8ZEI7BysKu0/ad55a4dc7d1d2efc2ab73053a2e6e01f/Deduplication_blog_-_OSI.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oRgJeyCT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/4bj8dCUSqBG8ZEI7BysKu0/ad55a4dc7d1d2efc2ab73053a2e6e01f/Deduplication_blog_-_OSI.jpg" alt="Deduplication blog - OSI" width="880" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Stop Duplication During ETL Jobs
&lt;/h3&gt;

&lt;p&gt;Stream-processing ETL jobs is another deduplication method. ETL jobs come with additional overhead to manage, require additional computing costs, are potential failure points with added complexity, and introduce latency to a system potentially needing high throughput. This involves deduplication during data stream consumption. The consumption outlets might include creating a compacted topic and/or introducing an ETL job with a common batch processing tool (e.g., Fivetran, Airflow, and Matillian).&lt;/p&gt;

&lt;p&gt;In order for deduplication to be effective using the stream-processing ETL jobs method, you must ensure the ETL jobs run throughout your system. Since data duplication can apply anywhere in a distributed system, ensuring architectures deduplicate in all places messages are passed is paramount.&lt;/p&gt;

&lt;p&gt;Stream processors can have an active processing window (open for a specific time) where duplicate messages can be detected and compacted, and out-of-order messages can be reordered. Messages can be duplicated if they are received outside the processing window. Furthermore, these stream processors must be maintained and can take considerable compute resources and operational overhead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Messages received outside of the active processing window can be duplicated. We do not recommend solving deduplication issues using this method alone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stop Duplication at Query Time
&lt;/h3&gt;

&lt;p&gt;Another deduplication method is to attempt to solve it at query time. However, this increases the complexity of your query, which is risky because query errors could be generated.&lt;/p&gt;

&lt;p&gt;For example, if your solution tracks messages using timestamps, and the duplicate messages are delayed by one second (instead of 50 milliseconds), the timestamp on the duplicate messages will not match your query syntax causing an error to be thrown.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Rockset Solves Duplication
&lt;/h2&gt;

&lt;p&gt;Rockset solves the duplication problem through unique &lt;a href="https://rockset.com/docs/ingest-transformation/"&gt;SQL-based transformations at ingest time&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rockset is a Mutable Database
&lt;/h3&gt;

&lt;p&gt;Rockset is a &lt;a href="https://rockset.com/blog/why-mutability-is-essential-for-real-time-data-analytics/"&gt;mutable database&lt;/a&gt; and allows for duplicate messages to be merged at ingest time. This system frees teams from the many cumbersome deduplication options covered earlier.&lt;/p&gt;

&lt;p&gt;Each document has a unique identifier called &lt;code&gt;_id&lt;/code&gt; that acts like a primary key. Users can specify this identifier at ingest time (e.g. during updates) using SQL-based transformations. When a new document arrives with the same &lt;code&gt;_id&lt;/code&gt;, the duplicate message merges into the existing record. This offers users a simple solution to the duplication problem.&lt;/p&gt;

&lt;p&gt;When you bring data into Rockset, you can build your own complex &lt;code&gt;_id&lt;/code&gt; key using SQL transformations that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identify a single key.&lt;/li&gt;
&lt;li&gt;Identify a composite key.&lt;/li&gt;
&lt;li&gt;Extract data from multiple keys.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rockset is fully mutable without an active window. As long as you specify messages with &lt;code&gt;_id&lt;/code&gt; or identify &lt;code&gt;_id&lt;/code&gt; within the document you are updating or inserting, incoming duplicate messages will be deduplicated and merged together into a single document.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rockset Enables Data Mobility
&lt;/h3&gt;

&lt;p&gt;Other analytics databases store data in fixed data structures, which require compaction, resharding and rebalancing. Any time there is a change to existing data, a major overhaul of the storage structure is required. Many data systems have active windows to avoid overhauls to the storage structure. As a result, if you map &lt;code&gt;_id&lt;/code&gt; to a record outside the active database, that record will fail. In contrast, Rockset users have a lot of data mobility and can update any record in Rockset at any time.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Customer Win With Rockset
&lt;/h2&gt;

&lt;p&gt;While we've spoken about the operational challenges with data deduplication in other systems, there's also a compute-spend element. Attempting deduplication at query time, or using ETL jobs can be computationally expensive for many use cases.&lt;/p&gt;

&lt;p&gt;Rockset can handle data changes, and it supports inserts, updates and deletes that benefit end users. Here’s an anonymous story of one of the users that I’ve worked closely with on their real-time analytics use case.&lt;/p&gt;

&lt;h3&gt;
  
  
  Customer Background
&lt;/h3&gt;

&lt;p&gt;A customer had a massive amount of data changes that created duplicate entries within their &lt;a href="https://rockset.com/comparisons/rockset-vs-data-warehouse"&gt;data warehouse&lt;/a&gt;. Every database change resulted in a new record, although the customer only wanted the current state of the data.&lt;/p&gt;

&lt;p&gt;If the customer wanted to put this data into a data warehouse that cannot map &lt;code&gt;_id&lt;/code&gt;, the customer would’ve had to cycle through the multiple events stored in their database. This includes running a base query followed by additional event queries to get to the latest value state. This process is extremely computationally expensive and time consuming.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rockset's Solution
&lt;/h3&gt;

&lt;p&gt;Rockset provided a more efficient deduplication solution to their problem. Rockset maps &lt;code&gt;_id&lt;/code&gt; so only the latest states of all records are stored, and all incoming events are deduplicated. Therefore the customer only needed to query the latest state. Thanks to this functionality, Rockset enabled this customer to reduce both the compute required, as well as the query processing time — efficiently delivering sub-second queries.&lt;/p&gt;

</description>
      <category>database</category>
      <category>deduplication</category>
      <category>sql</category>
      <category>olap</category>
    </item>
    <item>
      <title>How To Join Data in MongoDB</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Wed, 20 Apr 2022 16:00:00 +0000</pubDate>
      <link>https://dev.to/rocksetcloud/how-to-join-data-in-mongodb-539c</link>
      <guid>https://dev.to/rocksetcloud/how-to-join-data-in-mongodb-539c</guid>
      <description>&lt;p&gt;&lt;a href="https://www.mongodb.com/"&gt;MongoDB&lt;/a&gt; is one of the most popular databases for modern applications. It enables a more flexible approach to data modeling than traditional SQL databases. Developers can build applications more quickly because of this flexibility and also have multiple deployment options, from the cloud MongoDB Atlas offering through to the open-source Community Edition.&lt;/p&gt;

&lt;p&gt;MongoDB stores each record as a document with fields. These fields can have a range of flexible types and can even have other documents as values. Each document is part of a collection — think of a table if you’re coming from a relational paradigm. When you’re trying to create a document in a group that doesn’t exist yet, MongoDB creates it on the fly. There’s no need to create a collection and prepare a schema before you add data to it.&lt;/p&gt;

&lt;p&gt;MongoDB provides the MongoDB Query Language for performing operations in the database. When retrieving data from a collection of documents, we can search by field, apply filters and sort results in all the ways we’d expect. Plus, most languages have native object-relational mapping, such as Mongoose in JavaScript and Mongoid in Ruby.&lt;/p&gt;

&lt;p&gt;Adding relevant information from other collections to the returned data isn’t always fast or intuitive. Imagine we have two collections: a collection of users and a collection of products. We want to retrieve a list of all the users and show a list of the products they have each bought. We’d want to do this in a single query to simplify the code and reduce data transactions between the client and the database.&lt;/p&gt;

&lt;p&gt;We’d do this with a left outer join of the Users and Products tables in a SQL database. However, MongoDB isn’t a SQL database. Still, this doesn’t mean that it’s impossible to perform data joins — they just look slightly different than SQL databases. In this article, we’ll review strategies we can use to join data in MongoDB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Joining Data in MongoDB
&lt;/h2&gt;

&lt;p&gt;Let’s begin by discussing how we can join data in MongoDB. There are two ways to perform joins: using the &lt;code&gt;$lookup&lt;/code&gt; operator and denormalization. Later in this article, we’ll also look at some alternatives to performing data joins.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using the $lookup Operator
&lt;/h3&gt;

&lt;p&gt;Beginning with MongoDB version 3.2, the database query language includes the &lt;a href="https://docs.mongodb.com/v5.0/reference/operator/aggregation/lookup/#pipe._S_lookup"&gt;$lookup operator&lt;/a&gt;. MongoDB lookups occur as a stage in an &lt;a href="https://docs.mongodb.com/manual/core/aggregation-pipeline/"&gt;aggregation pipeline&lt;/a&gt;. This operator allows us to join two collections that are in the same database. It effectively adds another stage to the data retrieval process, creating a new array field whose elements are the matching documents from the joined collection. Let’s see what it looks like:&lt;/p&gt;

&lt;p&gt;Beginning with MongoDB version 3.2, the database query language includes the &lt;code&gt;$lookup&lt;/code&gt; operator. MongoDB lookups occur as a stage in an aggregation pipeline. This operator allows us to join two collections that are in the same database. It effectively adds another stage to the data retrieval process, creating a new array field whose elements are the matching documents from the joined collection. Let’s see what it looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.aggregate([{$lookup: 
    {
     from: "products", 
     localField: "product_id", 
     foreignField: "_id", 
     as: "products"
    }
}])

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that we’ve used the &lt;code&gt;$lookup&lt;/code&gt; operator in an aggregate call to the user’s collection. The operator takes an options object that has typical values for anyone who has worked with SQL databases. So, &lt;code&gt;from&lt;/code&gt; is the name of the collection that must be in the same database, and &lt;code&gt;localField&lt;/code&gt; is the field we compare to the &lt;code&gt;foreignField&lt;/code&gt; in the target database. Once we’ve got all matching products, we add them to an array named by the property.&lt;/p&gt;

&lt;p&gt;This approach is equivalent to an SQL query that might look like this, using a subquery:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT *, products
FROM users
WHERE products in (
  SELECT *
  FROM products
  WHERE id = users.product_id
);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or like this, using a left join:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT *
FROM users
LEFT JOIN products
ON user.product_id = products._id

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this operation can often meet our needs, the &lt;code&gt;$lookup&lt;/code&gt; operator introduces some disadvantages. Firstly, it matters at what stage of our query we use &lt;code&gt;$lookup&lt;/code&gt;. It can be challenging to construct more complex sorts, filters or combinations on our data in the later stages of a multi-stage aggregation pipeline. Secondly, &lt;code&gt;$lookup&lt;/code&gt; is a relatively slow operation, increasing our query time. While we’re only sending a single query internally, MongoDB performs multiple queries to fulfill our request.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Denormalization in MongoDB
&lt;/h3&gt;

&lt;p&gt;As an alternative to using the &lt;code&gt;$lookup&lt;/code&gt; operator, we can denormalize our data. This approach is advantageous if we often carry out multiple joins for the same query. Denormalization is common in SQL databases. For example, we can create an adjacent table to store our joined data in a SQL database.&lt;/p&gt;

&lt;p&gt;Denormalization is similar in MongoDB, with one notable difference. Rather than storing this data as a flat table, we can have nested documents representing the results of all our joins. This approach takes advantage of the flexibility of MongoDB’s rich documents. And, we’re free to store the data in whatever way makes sense for our application.&lt;/p&gt;

&lt;p&gt;For example, imagine we have separate MongoDB collections for products, orders, and customers. Documents in these collections might look like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Product&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "_id": 3,
    "name": "45' Yacht",
    "price": "250000",
    "description": "A luxurious oceangoing yacht."
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Customer&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "_id": 47,
    "name": "John Q. Millionaire",
    "address": "1947 Mt. Olympus Dr.",
    "city": "Los Angeles",
    "state": "CA",
    "zip": "90046"
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Order&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "_id": 49854,
    "product_id": 3,
    "customer_id": 47,
    "quantity": 3,
    "notes": "Three 45' Yachts for John Q. Millionaire. One for the east coast, one for the west coast, one for the Mediterranean".
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we denormalize these documents so we can retrieve all the data with a single query, our order document looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "_id": 49854,
    "product": {
        "name": "45' Yacht",
        "price": "250000",
        "description": "A luxurious oceangoing yacht."
    },
    "customer": {
        "name": "John Q. Millionaire",
        "address": "1947 Mt. Olympus Dr.",
        "city": "Los Angeles",
        "state": "CA",
        "zip": "90046"
    },
    "quantity": 3,
    "notes": "Three 45' Yachts for John Q. Millionaire. One for the east coast, one for the west coast, one for the Mediterranean".
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method works in practice because, during data writing, we store all the data we need in the top-level document. In this case, we’ve merged product and customer data into the order document. When we query the information now, we get it straight away. We don’t need any secondary or tertiary queries to retrieve our data. This approach increases the speed and efficiency of the data read operations. The trade-off is that it requires additional upfront processing and increases the time taken for each write operation.&lt;/p&gt;

&lt;p&gt;Copies of the product and every user who buys that product present an additional challenge. For a small application, this level of data duplication isn’t likely to be a problem. For a business-to-business e-commerce app, which has thousands of orders for each customer, this data duplication can quickly become costly in time and storage.&lt;/p&gt;

&lt;p&gt;Those nested documents aren’t relationally linked, either. If there’s a change to a product, we need to search for and update every product instance. This effectively means we must check each document in the collection since we won’t know ahead of time whether or not the change will affect it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternatives to Joins in MongoDB
&lt;/h2&gt;

&lt;p&gt;Ultimately, SQL databases handle joins better than MongoDB. If we find ourselves often reaching for &lt;code&gt;$lookup&lt;/code&gt; or a denormalized dataset, we might wonder if we’re using the right tool for the job. Is there a different way to leverage MongoDB for our application? Is there a way of achieving joins that might serve our needs better?&lt;/p&gt;

&lt;p&gt;Rather than abandoning MongoDB altogether, we could look for an alternative solution. One possibility is to use a secondary indexing solution that syncs with MongoDB and is optimized for analytics. For example, we can use &lt;a href="https://rockset.com"&gt;Rockset&lt;/a&gt;, a &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; database, to ingest directly from MongoDB change streams, which enables us to query our data with familiar SQL search, aggregation and join queries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We have a range of options for creating an enriched dataset by joining relevant elements from multiple collections. The first method is the &lt;code&gt;$lookup&lt;/code&gt; operator. This reliable tool allows us to do the equivalent of left joins on our MongoDB data. Or, we can prepare a denormalized collection that allows fast retrieval of the queries we require. As an alternative to these options, we can &lt;a href="https://rockset.com/docs/mongodb-atlas/"&gt;employ Rockset’s SQL analytics capabilities on data in MongoDB&lt;/a&gt;, regardless of how it’s structured.&lt;/p&gt;

&lt;p&gt;If you haven’t tried Rockset’s real-time analytics capabilities yet, why not have a go? Jump over to the documentation and learn more about how you can use &lt;a href="https://rockset.com/solutions/mongodb/"&gt;Rockset with MongoDB&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://rockset.com/"&gt;Rockset&lt;/a&gt; is the &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; database in the cloud for modern data teams. Get faster analytics on fresher data, at lower costs, by exploiting indexing over brute-force scanning.&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>rockset</category>
      <category>sql</category>
      <category>olap</category>
    </item>
    <item>
      <title>Rockset Beats ClickHouse and Druid on the Star Schema Benchmark (SSB)</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Tue, 05 Apr 2022 16:36:06 +0000</pubDate>
      <link>https://dev.to/rocksetcloud/rockset-beats-clickhouse-and-druid-on-the-star-schema-benchmark-ssb-4d46</link>
      <guid>https://dev.to/rocksetcloud/rockset-beats-clickhouse-and-druid-on-the-star-schema-benchmark-ssb-4d46</guid>
      <description>&lt;p&gt;A year ago we &lt;a href="https://rockset.com/blog/rockset-up-to-9x-faster-than-apache-druid-star-schema-benchmark/"&gt;evaluated Rockset on the Star Schema Benchmark (SSB)&lt;/a&gt;, an industry-standard benchmark used to measure the query performance of analytical databases. Subsequently, Altinity published ClickHouse’s results on the SSB. Recently, Imply published revised Apache Druid results on the SSB with denormalized numbers. With all the performance improvements we've been working on lately, we took another look at how these would affect Rockset's performance on the SSB.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rockset beat both ClickHouse and Druid query performance on the Star Schema Benchmark. Rockset is 1.67 times faster than ClickHouse with the same hardware configuration. And 1.12 times faster than Druid, even though Druid used 12.5% more compute.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rockset executed every query in the SSB suite in 88 milliseconds or less. Rockset is faster than ClickHouse in 10 of the 13 SSB queries. Rockset is also faster than Druid in 9 queries.&lt;/p&gt;

&lt;p&gt;The performance gains over ClickHouse and Druid are due to several enhancements we made recently that benefit Rockset users:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A new version of the on-disk format for the column-based index that has better compression, faster decoding and computations on compressed data.&lt;/li&gt;
&lt;li&gt;Leveraging more Single Instruction/Multiple Data (SIMD) instructions as part of the vectorized execution engine to take advantage of higher throughput offered by modern processors.&lt;/li&gt;
&lt;li&gt;The introduction of a custom block size policy in RocksDB to increase the throughput of large scans in the column-based index.&lt;/li&gt;
&lt;li&gt;The automated splitting of column-based clusters to improve the read throughput and ensure all column clusters are properly sized. &lt;/li&gt;
&lt;li&gt;A more efficient check for set containment to reduce compute costs.&lt;/li&gt;
&lt;li&gt;The caching of column-based clustering metadata to improve aggregation performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a result of these performance gains, users can build more interactive and responsive data applications using Rockset.&lt;/p&gt;

&lt;h2&gt;
  
  
  SSB Configuration &amp;amp; Results
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://www.cs.umb.edu/~poneil/StarSchemaB.PDF"&gt;SSB&lt;/a&gt; measures the performance of 13 queries typical of data applications. It is a benchmark based on &lt;a href="https://www.tpc.org/information/benchmarks5.asp#:~:text=The%20TPC%20Benchmark"&gt;TPC-H&lt;/a&gt; and designed for data warehouse workloads. More recently, it has been used to measure the performance of queries involving aggregations and metrics in column-oriented databases ClickHouse and Druid.&lt;/p&gt;

&lt;p&gt;To achieve resource parity, we used the same hardware configuration that Altinity used in its last published &lt;a href="https://rockset.com/comparisons/rockset-vs-clickhouse/"&gt;ClickHouse&lt;/a&gt; SSB performance benchmark. The hardware was a single m5.8xlarge Amazon EC2 instance. Imply has also released revised SSB numbers for Druid using a hardware configuration with more vCPU resources. Even so, Rockset was able to beat Druid’s numbers on absolute terms.&lt;/p&gt;

&lt;p&gt;We also scaled the dataset size to 100 GB and 600M rows of data, a scale factor of 100, just like Altinity and Imply did. As Altinity and Imply released detailed SSB performance results on denormalized data, we followed suit. This removed the need for query time joins, even though that is something Rockset is well-equipped to handle. &lt;/p&gt;

&lt;p&gt;All queries ran under 88 milliseconds on Rockset with  an aggregate runtime of 664 milliseconds across the entire suite of SSB queries. Clickhouse’s aggregate runtime was 1,112 milliseconds. Druid’s aggregate runtime was 747 milliseconds. With these results, Rockset shows an overall speedup of  1.67 over ClickHouse and 1.12 over Druid.&lt;/p&gt;

&lt;p&gt;&lt;a href="//images.ctfassets.net/1d31s1aajogl/5WUQrUmyYHTQEKwy4wex54/d910318aa45e81d99d1c938251681dcb/ssb-table.png" class="article-body-image-wrapper"&gt;&lt;img src="//images.ctfassets.net/1d31s1aajogl/5WUQrUmyYHTQEKwy4wex54/d910318aa45e81d99d1c938251681dcb/ssb-table.png" alt="ssb-table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1: Chart comparing ClickHouse, Druid and Rockset runtimes on SSB. The configuration of m5.8xlarge is 32 vCPUs and 128 GiB of memory. c5.9xlarge is 36 vCPUs and 72 GiB of memory.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="//images.ctfassets.net/1d31s1aajogl/3x2dxjn64yKOiAC6wQUNEp/c9de32e12b704c81beb49c854158089e/ssb-graph.png" class="article-body-image-wrapper"&gt;&lt;img src="//images.ctfassets.net/1d31s1aajogl/3x2dxjn64yKOiAC6wQUNEp/c9de32e12b704c81beb49c854158089e/ssb-graph.png" alt="ssb-graph"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 2: Graph showing ClickHouse, Druid and Rockset runtimes on SSB queries.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can dig further into the configuration and performance enhancements in the &lt;a href="https://rockset.com/Rockset_Star_Schema_Benchmark_April2022.pdf"&gt;Rockset Performance Evaluation on the Star Schema Benchmark&lt;/a&gt; whitepaper. This paper provides an overview of the benchmark data and queries, describes the configuration for running the benchmark and discusses the results from the evaluation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rockset Performance Enhancements
&lt;/h2&gt;

&lt;p&gt;The execution plan for all queries in the SSB benchmark is similar. They involve a clustered scan followed by evaluating functions, applying filters and calculating aggregations. The speed up in Rockset queries comes from a common  set of performance enhancements. So, we cover the performance enhancements that contributed to the query speed in the benchmark below.&lt;/p&gt;

&lt;h3&gt;
  
  
  New On-Disk Format for the Column-Based Index
&lt;/h3&gt;

&lt;p&gt;Rockset uses its &lt;a href="https://rockset.com/blog/how-rocksets-converged-index-powers-real-time-analytics/"&gt;Converged Index&lt;/a&gt; to organize and retrieve data efficiently and quickly for analytics. The Converged Index is composed of a search index, column-based index and a row store. Rockset introduced a new on-disk format for the column-based index that supports dictionary encoding for strings. &lt;/p&gt;

&lt;p&gt;This means that if the same string is repeated multiple times within one chunk of data in the column-based index, the string is only stored on disk once, and we just store the index of that string. This reduces space usage on disk, and since the data is more compact, it is faster to load from disk or memory. We continue to store the strings in dictionary encoded format in memory, and we can compute on that format. The new columnar format also has other advantages, like handling null values more efficiently, and it is more extensible.&lt;/p&gt;

&lt;h3&gt;
  
  
  SIMD Vectorized Query Execution
&lt;/h3&gt;

&lt;p&gt;Query execution operators exchange and process data chunks, which are organized in a columnar format. In vectorized query execution, operations are performed on a set of values rather than one value at a time in a data chunk for more efficient query execution. With SIMD instructions, we leverage modern processors that can compute on 256 bits or 512 bits of data at a time with a single CPU instruction.&lt;/p&gt;

&lt;p&gt;For example, the &lt;code&gt;_mm256_cmpeq_epi64&lt;/code&gt; intrinsic can compare four 64-bit integers in a single instruction. For batch processing operations, this can substantially increase throughput. The comparison itself isn’t the end of the story though. SIMD instructions typically operate within a lane - so if you use four 64-bit inputs, you get four 64-bit outputs. That means instead of getting booleans as outputs, you get four 64-bit integers at the output. Typically when operating on booleans, you either want an array of booleans as the output, or a bitmask. We took great care to optimize that conversion step to see the maximum possible performance gain from SIMD.&lt;/p&gt;

&lt;h3&gt;
  
  
  RocksDB Block Size
&lt;/h3&gt;

&lt;p&gt;RocksDB is a high-performance embedded storage engine used by modern datastores like Kafka Streams, ksqlDB and Apache Flink. Rockset stores its indexes on RocksDB. As the SSB queries access data using the column-based index, larger storage blocks were configured for that index to improve throughput.&lt;/p&gt;

&lt;p&gt;RocksDB divides data into blocks. These blocks are the unit of data lookup for various operations, like reading from disk or reading from RocksDB’s in-memory block cache. The &lt;a href="https://github.com/facebook/rocksdb/wiki/Space-Tuning#block-size"&gt;size of these blocks&lt;/a&gt; is configurable. Larger blocks help with throughput for large scans because you need to do fewer total lookups in the block cache and fewer random accesses to main memory. Smaller blocks help with performance for point lookups because if you only need one key you can load less surrounding data. The cost of loading a large block does not amortize well if you only need 1% of the data in it. You also waste space in the cache by storing data that was not recently accessed. &lt;/p&gt;

&lt;p&gt;For Rockset’s inverted index and row-based index, which are often used for point lookups, a small block size makes sense. For the column-based index though, which is often used for bulk scans, a much larger block size improves throughput. We created a custom block size policy under the hood to tune the block size for each index independently and increased the size of the column-based index blocks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance Gains for Rockset Users
&lt;/h2&gt;

&lt;p&gt;Rockset is 1.67 times faster than ClickHouse and 1.12 times faster than Druid on the Star Schema Benchmark. Data engineering teams have over the years put up with a tremendous amount of complexity in the name of performance when using ClickHouse and Druid. Teams have traditionally had to do time-consuming data preparation, cluster tuning and infrastructure management in order to meet the performance requirements of their application. Rockset, with Converged Indexing and built-in data connectors, is the easiest real-time analytics platform to scale. We’re happy to share it also has the fastest query performance. &lt;a href="https://rockset.com/create/"&gt;Try Rockset&lt;/a&gt; and experience the performance enhancements on your own dataset and queries. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://rockset.com/Rockset_Star_Schema_Benchmark_April2022.pdf"&gt;&lt;img src="//images.ctfassets.net/1d31s1aajogl/5VdHan4kCTLoTBpNEm34LE/2b7e76f8c7e8765ccc4370af15f9e814/ssb-whitepaper.png" alt="ssb-whitepaper"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authors:&lt;/strong&gt; Ben Hannel, Software Engineering, and Julie Mills, Product Marketing&lt;/p&gt;




&lt;p&gt;&lt;a href="https://rockset.com/"&gt;Rockset&lt;/a&gt; is the &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; database in the cloud for modern data teams. Get faster analytics on fresher data, at lower costs, by &lt;a href="https://rockset.com/docs/what-is-rockset/"&gt;exploiting indexing over brute-force scanning&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>druid</category>
      <category>realtime</category>
      <category>analytics</category>
      <category>clickhouse</category>
    </item>
    <item>
      <title>Streaming Analytics With KSQL vs. a Real-Time Analytics Database</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Tue, 22 Mar 2022 13:00:00 +0000</pubDate>
      <link>https://dev.to/rocksetcloud/streaming-analytics-with-ksql-vs-a-real-time-analytics-database-39p3</link>
      <guid>https://dev.to/rocksetcloud/streaming-analytics-with-ksql-vs-a-real-time-analytics-database-39p3</guid>
      <description>&lt;p&gt;By &lt;a href="https://www.lewisgavin.co.uk/"&gt;Lewis Gavin&lt;/a&gt;, Data Architect&lt;/p&gt;

&lt;p&gt;In 2019, &lt;a href="https://www.gartner.com/smarterwithgartner/gartner-top-10-data-analytics-trends"&gt;Gartner predicted&lt;/a&gt; that “&lt;em&gt;by 2022, more than half of major new business systems will incorporate continuous intelligence that uses &lt;strong&gt;real-time context data&lt;/strong&gt; to improve decisions&lt;/em&gt;,” and users have grown to expect real-time data, especially since the rise of social networks.&lt;/p&gt;

&lt;p&gt;Companies are adopting real-time data for many reasons, including providing seamless and personalized experiences to users when interacting with services, and enabling real-time, data-driven decision making.&lt;/p&gt;

&lt;p&gt;As the requirement for real-time data has grown, so have the technologies that enable it. &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;Real-time analytics&lt;/a&gt; can be achieved in a number of ways, but approaches can generally be split into two camps: streaming analytics and analytics databases.&lt;/p&gt;

&lt;p&gt;Streaming analytics happens inline, as data is streamed from one place to another. Analytics happens continuously and in real time, as data is fed through the pipeline. Analytics databases ingest data in as near real time as possible, and allow fast analytical queries to be done on this data.&lt;/p&gt;

&lt;p&gt;In this post, we’ll talk through two technologies that implement these techniques: &lt;a href="https://rockset.com/sql-on-kafka/"&gt;ksqlDB&lt;/a&gt;, which provides streaming analytics, and Rockset, a real-time analytics database. We’ll dive into the pros and cons of each approach so you can decide which is right for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Streaming Analytics
&lt;/h2&gt;

&lt;p&gt;To deal with the scale and speed of the data being generated, a common pattern is to put this data onto a queue or stream. This decouples the mechanism for transporting the data away from any processing that you want to take place on the data. However, with this data being streamed in real-time, it makes sense to also process and analyze it in real-time, especially if you have a genuine use case for up-to-date analytics.&lt;/p&gt;

&lt;p&gt;To overcome this, Confluent developed kqlDB. Developed to work with &lt;a href="https://rockset.com/sql-on-kafka/"&gt;Apache Kafka&lt;/a&gt;, ksqlDB provides an SQL-like interface to data streams, allowing for filtering, aggregations and even joins across data streams. ksqlDB uses Kafka as the storage engine and then works as the compute engine. It also has built-in connectors for external data sources, such as connecting to databases over JDBC so they can be brought into Kafka to be joined with a real-time stream for enrichment.&lt;/p&gt;

&lt;p&gt;You can perform analytics in two ways: pull queries or push queries. Pull queries allow you to look up results at a specific point in time and execute the query on the stream as a one-off. This is similar to running a query on a database where you execute the query and a result is returned; if you want to refresh the result, you run the query again. This is useful for synchronous applications and often run with lower latency, as the stream data can be fed into a materialized view, which is kept up to date automatically, so there is less work for the query to do.&lt;/p&gt;

&lt;p&gt;Push queries allow you to subscribe to a table or a stream, and as the data is updated downstream, the query results will also reflect these updates in real-time. You execute the query once and the result changes as the data changes in the stream. This is a powerful use case for stream analytics as it allows you to subscribe to the result of a calculation on the data instead of subscribing to the data feed itself.&lt;/p&gt;

&lt;p&gt;For example, let’s say you have a taxi app. When you request a taxi, the driver accepts the ride and then on the screen you are shown the driver's location and your location and given an estimated time of arrival. To display the driver’s current location and the estimated time of arrival, you need to understand the driver’s position in real time and then from that continuously calculate the estimated time to arrive as the driver’s location updates.&lt;/p&gt;

&lt;p&gt;You could do this in two ways. The first way is to frequently poll the driver’s location and every time you retrieve the location, display the new position on the screen and also perform the calculation to estimate their arrival time. Alternatively, you could use stream analytics.&lt;/p&gt;

&lt;p&gt;The second way is to continuously stream the driver’s and the user’s locations in real-time. This same stream can be used to obtain the driver’s location for display purposes and also, by using a ksqlDB push query, you can calculate the time of arrival. Your application is then subscribed to the output from this push query and whenever the time of arrival changes it is automatically updated on the screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-Time Analytics Database
&lt;/h2&gt;

&lt;p&gt;An analytics database, as its name suggests, allows for analytics on data stored in a database. Historically, this could mean batch ingesting data into a database and then performing analytical queries on that data. However, tools like Rockset allow you to keep the benefits of a database but provide tools to perform analytics in near real-time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--es0__te---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/3VVpkdMsqxBKxy39gc11Nw/4bf6895492d1d40854610ae04a3d17e4/ksql-strreaming-analytics.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--es0__te---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/3VVpkdMsqxBKxy39gc11Nw/4bf6895492d1d40854610ae04a3d17e4/ksql-strreaming-analytics.png" alt="ksql-strreaming-analytics" width="880" height="430"&gt;&lt;/a&gt;Fig 1. Difference between streaming analytics and real-time analytics database&lt;/p&gt;

&lt;p&gt;Rockset provides out-of-the-box data connectors that allow data to be streamed into their analytics database. Rather than analyzing the data as it is streamed, the data is streamed into the database as close to real time as possible. Then, the analytics can take place on the data at rest. As shown in Fig 1, streaming analytics takes place on the stream itself whereas analytics databases ingest the data in real time and analytics is performed on the database.&lt;/p&gt;

&lt;p&gt;There are a number of benefits to storing the data in a database. Firstly you can index the data according to the use case to increase performance and reduce query latency. Unfortunately, creating bespoke indexes in order to make queries run quickly adds significant administrative overhead. And if the database needs bespoke indexes to perform well, then users submitting ad hoc queries are not going to have a great experience. Rockset solved this problem with the &lt;a href="https://rockset.com/blog/converged-indexing-the-secret-sauce-behind-rocksets-fast-queries/"&gt;Converged Index&lt;/a&gt; and an &lt;a href="https://rockset.com/whitepapers/rockset-concepts-designs-and-architecture/"&gt;SQL engine implementation&lt;/a&gt; that doesn't require administrators to create bespoke indexes.&lt;/p&gt;

&lt;p&gt;With streaming analytics, the focus is often on what is happening right now and although analytics databases support this, they also enable analytics across larger historical data when required.&lt;/p&gt;

&lt;p&gt;Some modern analytics databases also support schemaless ingest and can infer the schema on read to remove the burden of defining the schema upfront. For example, ksqlDB can connect to a Kafka topic that accepts unstructured data. However for ksqlDB to query this data, the schema of the underlying data needs to be defined upfront. On the other hand, modern analytics databases like Rockset allow the data to be ingested into a collection without defining the schema. This allows for flexible querying of the data, especially as the structure of the data evolves over time, as it doesn’t require any schema modifications to access the new properties.&lt;/p&gt;

&lt;p&gt;Finally, cloud native analytics databases often separate the storage and compute resources. This gives you the ability to scale them independently. This is vital if you have applications with high query per second (QPS) workloads, as when your system needs to deal with a spike in queries. You can easily scale the compute to meet this demand without incurring extra storage costs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which Should I Use?
&lt;/h2&gt;

&lt;p&gt;Overall, which system to use will ultimately depend on your use case. If your data is already flowing through Kafka topics and you want to run some real-time queries on this data in-flight, then ksqlDB may be the right choice. It will fulfil your use case and means you don’t have to invest in extra infrastructure to ingest this data into an analytics database. Remember, streaming analytics allows you to transform, filter and aggregate events as data is streamed in and your application can then subscribe to these results to get continuously updated results.&lt;/p&gt;

&lt;p&gt;If your use cases are more varied, then a real-time analytics database like Rockset may be the right choice. Analytics databases are ideal if you have data from many different systems that you want to join together, as you can delay joins until query time to get the most up-to-date data. If you need to support ad-hoc queries on historical datasets on top of real-time analytics and require the compute and storage to be scaled separately (important if you have high or variable query concurrency), then a real-time analytics database is likely the right option.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://rockset.com/"&gt;Rockset&lt;/a&gt; is the &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; database in the cloud for modern data teams. Get faster analytics on fresher data, at lower costs, by &lt;a href="https://rockset.com/docs/what-is-rockset/"&gt;exploiting indexing over brute-force scanning&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>ksql</category>
      <category>realtimeanalytics</category>
      <category>streaming</category>
    </item>
    <item>
      <title>What Do I Do When My Snowflake Query Is Slow? Part 2: Solutions</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Wed, 26 Jan 2022 08:00:00 +0000</pubDate>
      <link>https://dev.to/rocksetcloud/what-do-i-do-when-my-snowflake-query-is-slow-part-2-solutions-18m6</link>
      <guid>https://dev.to/rocksetcloud/what-do-i-do-when-my-snowflake-query-is-slow-part-2-solutions-18m6</guid>
      <description>&lt;p&gt;Snowflake’s data cloud enables companies to store and share data, then analyze this data for business intelligence. Although Snowflake is a great tool, sometimes querying vast amounts of data runs slower than your applications — and users — require.&lt;/p&gt;

&lt;p&gt;In our first article, &lt;a href="https://rockset.com/blog/what-do-i-do-when-my-snowflake-query-is-slow-part-1-diagnosis/"&gt;&lt;em&gt;What Do I Do When My Snowflake Query Is Slow? Part 1: Diagnosis&lt;/em&gt;&lt;/a&gt;, we discussed how to diagnose slow Snowflake query performance. Now it’s time to address those issues.&lt;/p&gt;

&lt;p&gt;We’ll cover Snowflake performance tuning, including reducing queuing, using result caching, tackling disk spilling, rectifying row explosion, and fixing inadequate pruning. We’ll also discuss alternatives for &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; that might be what you’re looking for if you are in need of better real-time query performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reduce Queuing
&lt;/h2&gt;

&lt;p&gt;Snowflake lines up queries until resources are available. It’s not good for queries to stay queued too long, as they will be aborted. To prevent queries from waiting too long, you have two options: set a timeout or adjust concurrency.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set a Timeout
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;STATEMENT_QUEUED_TIMEOUT_IN_SECOND&lt;/code&gt;S to define how long your query should stay queued before aborting. With a default value of 0, there is no timeout.&lt;/p&gt;

&lt;p&gt;Change this number to abort queries after a specific time to avoid too many queries queuing up. As this is a session-level query, you can set this timeout for particular sessions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adjust the Maximum Concurrency Level
&lt;/h3&gt;

&lt;p&gt;The total load time depends on the number of queries your warehouse executes in parallel. The more queries that run in parallel, the harder it is for the warehouse to keep up, impacting Snowflake performance.&lt;/p&gt;

&lt;p&gt;To rectify this, use Snowflake’s &lt;code&gt;MAX_CONCURRENCY_LEVEL&lt;/code&gt; parameter. Its default value is 8, but you can set the value to the number of resources you want to allocate.&lt;/p&gt;

&lt;p&gt;Keeping the &lt;code&gt;MAX_CONCURRENCY_LEVEL&lt;/code&gt; low helps improve execution speed, even for complex queries, as Snowflake allocates more resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Result Caching
&lt;/h2&gt;

&lt;p&gt;Every time you execute a query, it caches, so Snowflake doesn’t need to spend time retrieving the same results from cloud storage in the future.&lt;/p&gt;

&lt;p&gt;One way to retrieve results directly from the cache is by &lt;code&gt;RESULT_SCAN&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Fox example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select * from table(result_scan(last_query_id()))

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;LAST_QUERY_ID&lt;/code&gt; is the previously executed query. &lt;code&gt;RESULT_SCAN&lt;/code&gt; brings the results directly from the cache.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tackle Disk Spilling
&lt;/h2&gt;

&lt;p&gt;When data spills to your local machine, your operations must use a small warehouse. Spilling to remote storage is even slower.&lt;/p&gt;

&lt;p&gt;To tackle this issue, move to a more extensive warehouse with enough memory for code execution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  alter warehouse mywarehouse
        warehouse_size = XXLARGE
                   auto_suspend = 300
                      auto_resume = TRUE;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code snippet enables you to scale up your warehouse and suspend query execution automatically after 300 seconds. If another query is in line for execution, this warehouse resumes automatically after resizing is complete.&lt;/p&gt;

&lt;p&gt;Restrict the result display data. Choose the columns you want to display and avoid the columns you don’t need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  select last_name 
       from employee_table 
          where employee_id = 101;

  select first_name, last_name, country_code, telephone_number, user_id from
  employee_table 
       where employee_type like "%junior%";

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first query above is specific as it retrieves the last name of a particular employee. The second query retrieves all the rows for the employee_type of junior, with multiple other columns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rectify Row Explosion
&lt;/h2&gt;

&lt;p&gt;Row explosion happens when a &lt;code&gt;JOIN&lt;/code&gt; query retrieves many more rows than expected. This can occur when your join accidentally creates a cartesian product of all rows retrieved from all tables in your query.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use the Distinct Clause
&lt;/h3&gt;

&lt;p&gt;One way to reduce row explosion is by using the &lt;code&gt;DISTINCT&lt;/code&gt; clause that neglects duplicates.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  SELECT DISTINCT a.FirstName, a.LastName, v.District
  FROM records a 
  INNER JOIN resources v
  ON a.LastName = v.LastName
  ORDER BY a.FirstName;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this snippet, Snowflake only retrieves the distinct values that satisfy the condition.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use Temporary Tables
&lt;/h3&gt;

&lt;p&gt;Another option to reduce row explosion is by using temporary tables.&lt;/p&gt;

&lt;p&gt;This example shows how to create a temporary table for an existing table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  CREATE TEMPORARY TABLE tempList AS 
      SELECT a,b,c,d FROM table1
          INNER JOIN table2 USING (c);

  SELECT a,b FROM tempList
      INNER JOIN table3 USING (d);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Temporary tables exist until the session ends. After that, the user cannot retrieve the results.&lt;/p&gt;

&lt;h3&gt;
  
  
  Check Your Join Order
&lt;/h3&gt;

&lt;p&gt;Another option to fix row explosion is by checking your join order. Inner joins may not be an issue, but the table access order impacts the output for outer joins.&lt;/p&gt;

&lt;p&gt;Snippet one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  orders LEFT JOIN products 
      ON products.id = products.id
    LEFT JOIN entries
      ON entries.id = orders.id
      AND entries.id = products.id

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Snippet two:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  orders LEFT JOIN entries 
      ON entries.id = orders.id
    LEFT JOIN products
      ON products.id = orders.id
      AND products.id = entries.id

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In theory, outer joins are neither associative nor commutative. Thus, snippet one and snippet two do not return the same results. Be aware of the join type you use and their order to save time, retrieve the expected results, and avoid row explosion issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix Inadequate Pruning
&lt;/h2&gt;

&lt;p&gt;While running a query, Snowflake prunes micro-partitions, then the remaining partitions’ columns. This makes scanning easy because Snowflake now does not have to go through all the partitions.&lt;/p&gt;

&lt;p&gt;However, pruning does not happen perfectly all the time. Here is an example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wUCcDpkB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/4qItsQfBI877B08dH8Mk1L/9e4bd9ac57d21d537d0baad946030014/slow-snowflake-queries-image1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wUCcDpkB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/4qItsQfBI877B08dH8Mk1L/9e4bd9ac57d21d537d0baad946030014/slow-snowflake-queries-image1.png" alt="slow-snowflake-queries-image1" width="692" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When executing the query, the filter removes about 94 percent of the rows. Snowflake prunes the remaining partitions. That means the query scanned only a portion of the four percent of the rows retrieved.&lt;/p&gt;

&lt;p&gt;Data clustering can significantly improve this. You can cluster a table when you create it or when you alter an existing table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  CREATE TABLE recordsTable (C1 INT, C2 INT) CLUSTER BY (C1, C2);

  ALTER TABLE recordsTable CLUSTER BY (C1, C2);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Data clustering has limitations. Tables must have a large number of records and shouldn’t change frequently. The right time to cluster is when you know the query is slow, and you know that you can enhance it.&lt;/p&gt;

&lt;p&gt;In 2020, Snowflake deprecated the manual re-clustering feature, so that is not an option anymore.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up Snowflake Performance Issues
&lt;/h2&gt;

&lt;p&gt;We explained how to use queuing parameters, efficiently use Snowflake’s cache, and fix disk spilling and exploding rows. It’s easy to implement all these methods to help improve your Snowflake query performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Another Strategy for Improving Query Performance: Indexing
&lt;/h3&gt;

&lt;p&gt;Snowflake can be a good solution for business intelligence, but it’s not always the optimum choice for every use case, for example, scaling real-time analytics, which requires speed. For that, consider supplementing Snowflake with a database like &lt;a href="https://rockset.com"&gt;Rockset&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;High-performance real-time queries and low latency are Rockset's core features. Rockset provides less than &lt;a href="https://rockset.com/blog/rockset-1-billion-events-in-a-day-with-1-second-data-latency/"&gt;one second of data latency&lt;/a&gt; on large data sets, making new data ready to query quickly. Rockset excels at data indexing, which Snowflake doesn’t do, and it &lt;a href="https://rockset.com/blog/converged-indexing-the-secret-sauce-behind-rocksets-fast-queries/"&gt;indexes &lt;em&gt;all&lt;/em&gt; the fields&lt;/a&gt;, making it faster for your application to scan through and provide real-time analytics. Rockset is far more compute-efficient than Snowflake, delivering queries that are both fast and economical.&lt;/p&gt;

&lt;p&gt;Rockset is an excellent complement to your Snowflake data warehouse. &lt;a href="https://rockset.com/create/"&gt;Sign up&lt;/a&gt; for your free Rockset trial to see how we can help drive your real-time analytics.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://rockset.com/"&gt;Rockset&lt;/a&gt; is the &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; database in the cloud for modern data teams. Get faster analytics on fresher data, at lower costs, by exploiting indexing over brute-force scanning.&lt;/p&gt;

</description>
      <category>snowflake</category>
      <category>realtimeanalytics</category>
      <category>queries</category>
      <category>datawarehouse</category>
    </item>
    <item>
      <title>What Do I Do When My Snowflake Query Is Slow? Part 1: Diagnosis</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Thu, 20 Jan 2022 18:00:00 +0000</pubDate>
      <link>https://dev.to/rocksetcloud/what-do-i-do-when-my-snowflake-query-is-slow-part-1-diagnosis-39k3</link>
      <guid>https://dev.to/rocksetcloud/what-do-i-do-when-my-snowflake-query-is-slow-part-1-diagnosis-39k3</guid>
      <description>&lt;p&gt;&lt;em&gt;Because &lt;a href="https://rockset.com"&gt;Rockset&lt;/a&gt; helps organizations achieve the data freshness and query speeds needed for &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt;, we sometimes are asked about approaches to improving query speed in databases in general, and in popular databases such as Snowflake, MongoDB, DynamoDB, MySQL and others. We turn to industry experts to get their insights and we pass on their recommendations. In this case, the series of two posts that follow address how to improve query speed in Snowflake.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Every developer wants peak performance from their software services. When it comes to Snowflake performance issues, you may have decided that the occasional slow query is just something that you have to live with, right? Or maybe not. In this post we’ll discuss why Snowflake queries are slow and options you have to achieve better Snowflake query performance.&lt;/p&gt;

&lt;p&gt;It’s not always easy to tell why your Snowflake queries are running slowly, but before you can fix the problem, you have to know what’s happening. In part one of this two-part series, we’ll help you diagnose why your Snowflake queries are executing slower than usual. In our second article we’ll look at the best options for improving Snowflake query performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Diagnosing Queries in Snowflake
&lt;/h2&gt;

&lt;p&gt;First, let’s unmask common misconceptions of why Snowflake queries are slow. Your hardware and operating system (OS) don’t play a role in execution speed because Snowflake runs as a cloud service.&lt;/p&gt;

&lt;p&gt;The network could be one reason for slow queries, but it’s not significant enough to slow execution all the time. So, let’s dive into the other reasons your queries might be lagging.&lt;/p&gt;

&lt;h3&gt;
  
  
  Check the Information Schema
&lt;/h3&gt;

&lt;p&gt;In short, the &lt;code&gt;INFORMATION_SCHEMA&lt;/code&gt; is the blueprint for every database you create in Snowflake. It allows you to view historical data on tables, warehouses, permissions, and queries.&lt;/p&gt;

&lt;p&gt;You cannot manipulate its data as it is read-only. Among the principal functions in the &lt;code&gt;INFORMATION_SCHEMA&lt;/code&gt;, you will find the &lt;code&gt;QUERY_HISTORY&lt;/code&gt; and &lt;code&gt;QUERY_HISTORY_BY_*&lt;/code&gt; tables. These tables help uncover the causes of slow Snowflake queries. You'll see both of these tables in use below.&lt;/p&gt;

&lt;p&gt;Keep in mind that this tool only returns data to which your Snowflake account has access.&lt;/p&gt;

&lt;h3&gt;
  
  
  Check the Query History Page
&lt;/h3&gt;

&lt;p&gt;Snowflake’s query history page retrieves columns with valuable information. In our case, we get the following columns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;EXECUTION_STATUS&lt;/code&gt; displays the state of the query, whether it is running, queued, blocked, or success.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;QUEUED_PROVISIONING_TIME&lt;/code&gt; displays the time spent waiting for the allocation of a suitable warehouse.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;QUEUED_REPAIR_TIME&lt;/code&gt; displays the time it takes to repair the warehouse.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;QUEUED_OVERLOAD_TIME&lt;/code&gt; displays the time spent while an ongoing query is overloading the warehouse.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overloading is the more common phenomenon, and &lt;code&gt;QUEUED_OVERLOAD_TIME&lt;/code&gt; serves as a crucial diagnosing factor.&lt;/p&gt;

&lt;p&gt;Here is a sample query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      select *
      from table(information_schema.query_history_by_session())
      order by start_time;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives you the last 100 queries that Snowflake executed in the current session. You can also get the query history based on the user and the warehouse as well.&lt;/p&gt;

&lt;h3&gt;
  
  
  Check the Query Profile
&lt;/h3&gt;

&lt;p&gt;In the previous section, we saw what happens when multiple queries are affected collectively. It’s equally important to address the individual queries. For that, use the query profile option.&lt;/p&gt;

&lt;p&gt;You can find a query’s profile on Snowflake’s &lt;strong&gt;History&lt;/strong&gt; tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tKHM2Knt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/WGtgc5gzMgKax4VRYW2F7/728011344f03d641ae03dddd607586e7/snowflakequeryperformance2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tKHM2Knt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/WGtgc5gzMgKax4VRYW2F7/728011344f03d641ae03dddd607586e7/snowflakequeryperformance2.png" alt="snowflakequeryperformance2" width="880" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The query profile interface looks like an advanced flowchart with step-by-step query execution. You should focus mainly on the operator tree and nodes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wAj7avJa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/1uLxi0tTWc8h74UUJzb5h6/d6899da79503e1a8a232ca68645038f4/snowflakequeryperformance4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wAj7avJa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/1uLxi0tTWc8h74UUJzb5h6/d6899da79503e1a8a232ca68645038f4/snowflakequeryperformance4.png" alt="snowflakequeryperformance4" width="880" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The operator nodes are spread out based on their execution time. Any operation that consumed over one percent of the total execution time appears in the operator tree.&lt;/p&gt;

&lt;p&gt;The pane on the right side shows the query’s execution time and attributes. From there, you can figure out which step took too much time and slowed the query.&lt;/p&gt;

&lt;h3&gt;
  
  
  Check Your Caching
&lt;/h3&gt;

&lt;p&gt;To execute a query and fetch the results, it might take 500 milliseconds. If you use that query frequently to fetch the same results, Snowflake gives you the option to cache it so the next time it is faster than 500 milliseconds.&lt;/p&gt;

&lt;p&gt;Snowflake caches data in the result cache. When it needs data, it checks the result cache first. If it does not find data, it checks the local hard drive. If it still does not find the data, it checks the remote storage.&lt;/p&gt;

&lt;p&gt;Retrieving data from the result cache is faster than from the hard drive or remote memory. So, it is best practice to use the result cache effectively. Data remains in the result cache for 24 hours. After that, you have to execute the query again to get the data from the hard disk.&lt;/p&gt;

&lt;p&gt;You can check out how effectively Snowflake used the result cache. Once you execute the query using Snowflake, check the &lt;strong&gt;Query Profile&lt;/strong&gt; tab.&lt;/p&gt;

&lt;p&gt;You find out how much Snowflake used the cache on a tab like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AEIzpcqO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/5EzLe1FnbcFpmPe8tc7vjm/aa7223a8cbdf1b0d521bd9d83deb94f1/snowflakequeryperformance3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AEIzpcqO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/5EzLe1FnbcFpmPe8tc7vjm/aa7223a8cbdf1b0d521bd9d83deb94f1/snowflakequeryperformance3.png" alt="snowflakequeryperformance3" width="628" height="248"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Check Snowflake Join Performance
&lt;/h3&gt;

&lt;p&gt;If you experience slowdowns during query execution, you should compare the expected output to the actual result. You could have encountered a row explosion.&lt;/p&gt;

&lt;p&gt;A row explosion is a query result that returns far more rows than anticipated. Therefore, it takes far more time than anticipated. For example, you might expect an output of four million records, but the outcome could be exponentially higher. This problem occurs with joins in your queries that combine rows from multiple tables. The join order matters. You can do two things: look for the join condition you used, or use Snowflake’s optimizer to see the join order.&lt;/p&gt;

&lt;p&gt;An easy way to determine whether this is the problem is to check the query profile for join operators that display more rows in the output than in the input links. To avoid a row explosion, ensure the query result does not contain more rows than all its inputs combined.&lt;/p&gt;

&lt;p&gt;Similar to the query pattern, using joins is in the hands of the developer. One thing is clear — bad joins result in slow Snowflake join performance, and slow queries.&lt;/p&gt;

&lt;h3&gt;
  
  
  Check for Disk Spilling
&lt;/h3&gt;

&lt;p&gt;Accessing data from a remote drive consumes more time than accessing it from a local drive or the result cache. But, when query results don’t fit on the local hard drive, Snowflake must use remote storage.&lt;/p&gt;

&lt;p&gt;When data moves to a remote hard drive, we call it disk spilling. Disk spilling is a common cause of slow queries. You can identify instances of disk spilling on the &lt;strong&gt;Query Profile&lt;/strong&gt; tab. Take a look at “Bytes spilled to local storage.”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QIoaIzB9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/2AAnmzjnYCeMPtt1VSMAtC/51737ccf0e77e05f6e24cf0d86efbf7e/snowflakequeryperformance5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QIoaIzB9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/2AAnmzjnYCeMPtt1VSMAtC/51737ccf0e77e05f6e24cf0d86efbf7e/snowflakequeryperformance5.png" alt="snowflakequeryperformance5" width="684" height="900"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, the execution time is over eight minutes, out of which only two percent was for the local disk IO. That means Snowflake did not access the local disk to fetch data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Check Queuing
&lt;/h3&gt;

&lt;p&gt;The warehouse may be busy executing other queries. Snowflake cannot start incoming queries until adequate resources are free. In Snowflake, we call this queuing.&lt;/p&gt;

&lt;p&gt;Queries are queued so as not to compromise Snowflake query performance. Queuing may happen because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The warehouse you are using is overloaded.&lt;/li&gt;
&lt;li&gt;Queries in line are consuming the necessary computing resources.&lt;/li&gt;
&lt;li&gt;Queries occupy all the cores in the warehouse.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can rely on the queue overload time as a clear indicator. To check this, look at the query history by executing the query below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      QUERY_HISTORY_BY_SESSION(
      [SESSION_ID =&amp;gt; &amp;lt;constant_expr&amp;gt;]
      [, END_TIME_RANGE_START =&amp;gt; &amp;lt;constant_expr&amp;gt;]
      [, END_TIME_RANGE_END =&amp;gt; &amp;lt;constant_expr&amp;gt;]
      [, RESULT_LIMIT =&amp;gt; &amp;lt;num&amp;gt;] )

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can determine how long a query should sit in the queue before Snowflake aborts it. To determine how long a query should remain in line before aborting it, set the value of the &lt;code&gt;STATEMENT_QUEUED_TIMEOUT_IN_SECONDS&lt;/code&gt; column. The default is zero, and it can take any number.&lt;/p&gt;

&lt;h3&gt;
  
  
  Analyze the Warehouse Load Chart
&lt;/h3&gt;

&lt;p&gt;Snowflake offers charts to read and interpret data. The warehouse load chart is a handy tool, but you need the &lt;strong&gt;MONITOR&lt;/strong&gt; privilege to view it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r4yzFAEp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/3WeOggcAVQ4rGMHvp6WmL8/9494df26450dcce7af41445c9ba75b42/snowflakequeryperformance1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r4yzFAEp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.ctfassets.net/1d31s1aajogl/3WeOggcAVQ4rGMHvp6WmL8/9494df26450dcce7af41445c9ba75b42/snowflakequeryperformance1.png" alt="snowflakequeryperformance1" width="880" height="303"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is an example chart for the past 14 days. When you hover over the bars, you find two statistics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Load from running queries — from the queries that are executing&lt;/li&gt;
&lt;li&gt;Load from queued queries — from all the queries waiting in the warehouse&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The total warehouse load is the sum of the running load and the queued load. When there is no contention for resources, this sum is one. The more the queued load, the longer it takes for your query to execute. Snowflake may have optimized the query, but it may take a while to execute because several other queries were ahead of it in the queue.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use the Warehouse Load History
&lt;/h3&gt;

&lt;p&gt;You can find data on warehouse loads using the &lt;code&gt;WAREHOUSE_LOAD_HISTORY&lt;/code&gt; query.&lt;/p&gt;

&lt;p&gt;Three parameters help diagnose slow queries:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;AVG_RUNNING&lt;/code&gt; — the average number of queries executing&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;AVG_QUEUED_LOAD&lt;/code&gt; — the average number of queries queued because the warehouse is overloaded&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;AVG_QUEUED_PROVISIONING&lt;/code&gt; — the average number of queries queued because Snowflake is provisioning the warehouse&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This query retrieves the load history of your warehouse for the past hour:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  use warehouse mywarehouse;

      select *
      from
      table(information_schema.warehouse_load_history(date_range_start=&amp;gt;dateadd
      ('hour',-1,current_timestamp())));

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Use the Maximum Concurrency Level
&lt;/h3&gt;

&lt;p&gt;Every Snowflake warehouse has a limited amount of computing power. In general, the larger (and more expensive) your Snowflake plan, the more computing horsepower it has.&lt;/p&gt;

&lt;p&gt;A Snowflake warehouse's &lt;code&gt;MAX_CONCURRENCY_LEVEL&lt;/code&gt; setting determines how many queries are allowed to run in parallel. In general, the more queries running simultaneously, the slower each of them. But if your warehouse's concurrency level is too low, it might cause the perception that queries are slow.&lt;/p&gt;

&lt;p&gt;If there are queries that Snowflake can't immediately execute because there are too many concurrent queries running, they end up in the query queue to wait their turn. If a query remains in the line for a long time, the user who ran the query may think the query itself is slow. And if a query stays queued for too long, it may be aborted before it even executes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps for Improving Snowflake Query Performance
&lt;/h2&gt;

&lt;p&gt;Your Snowflake query may run slowly for various reasons. Caching is effective but doesn’t happen for all your queries. Check your joins, check for disk spilling, and check to see if your queries are spending time stuck in the query queue.&lt;/p&gt;

&lt;p&gt;When investigating slow Snowflake query performance, the query history page, warehouse loading chart, and query profile all offer valuable data, giving you insight into what is going on.&lt;/p&gt;

&lt;p&gt;Now that you understand why your Snowflake query performance may not be all that you want it to be, you can narrow down possible culprits. Your next step is to get your hands dirty and fix them.&lt;/p&gt;

&lt;p&gt;Come back next week to check out the next article in this series, &lt;em&gt;What Do I Do When My Snowflake Query Is Slow? Part 2: Solutions&lt;/em&gt;, for tips on optimizing your Snowflake queries and other choices you can make if real-time query performance is a priority for you.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://rockset.com/"&gt;Rockset&lt;/a&gt; is the &lt;a href="https://rockset.com/real-time-analytics-explained/"&gt;real-time analytics&lt;/a&gt; database in the cloud for modern data teams. Get faster analytics on fresher data, at lower costs, by exploiting indexing over brute-force scanning.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Real-Time Analytics Podcast Episode 10: Self-service data analytics with Grafbase CEO, Fredrik Bjork</title>
      <dc:creator>Shawn Adams</dc:creator>
      <pubDate>Tue, 05 Oct 2021 14:26:42 +0000</pubDate>
      <link>https://dev.to/rocksetcloud/real-time-analytics-podcast-episode-10-self-service-data-analytics-with-grafbase-ceo-fredrik-bjork-4g0i</link>
      <guid>https://dev.to/rocksetcloud/real-time-analytics-podcast-episode-10-self-service-data-analytics-with-grafbase-ceo-fredrik-bjork-4g0i</guid>
      <description>&lt;p&gt;Fredrik Bjork has traversed the data space, creating a gaming social network, scaling the RealReal's marketplace and now investing in the data startups. Hear how the data experience has changed with each endeavor and what trends he's must bullish on in this podcast.&lt;/p&gt;

&lt;p&gt;Listen to this podcast: &lt;a href="https://rockset.com/podcasts/the-rise-of-real-time-analytics/episode10-self-service-data-analytics-in-cybersecurity/"&gt;https://rockset.com/podcasts/the-rise-of-real-time-analytics/episode10-self-service-data-analytics-in-cybersecurity/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>database</category>
      <category>serverless</category>
      <category>podcast</category>
    </item>
  </channel>
</rss>
