<?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: Saiyam Jain</title>
    <description>The latest articles on DEV Community by Saiyam Jain (@cybersaiyam).</description>
    <link>https://dev.to/cybersaiyam</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%2F531743%2Fb1f91492-9635-4afd-89cd-0ca63e2e47b9.jpeg</url>
      <title>DEV Community: Saiyam Jain</title>
      <link>https://dev.to/cybersaiyam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cybersaiyam"/>
    <language>en</language>
    <item>
      <title>RabbitMQ Explained: How It Works, How It Differs from Kafka, and Where It Fits in Real Systems</title>
      <dc:creator>Saiyam Jain</dc:creator>
      <pubDate>Thu, 28 May 2026 20:07:16 +0000</pubDate>
      <link>https://dev.to/cybersaiyam/rabbitmq-explained-how-it-works-how-it-differs-from-kafka-and-where-it-fits-in-real-systems-5ak8</link>
      <guid>https://dev.to/cybersaiyam/rabbitmq-explained-how-it-works-how-it-differs-from-kafka-and-where-it-fits-in-real-systems-5ak8</guid>
      <description>&lt;p&gt;Modern applications are no longer simple monoliths. Today’s systems handle millions of requests, asynchronous workflows, distributed microservices, and background processing — all at once.&lt;/p&gt;

&lt;p&gt;To make this reliable and scalable, applications rely on &lt;strong&gt;message brokers&lt;/strong&gt;. One of the most widely used is &lt;strong&gt;RabbitMQ&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this article, we’ll cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What RabbitMQ is and how it works internally&lt;/li&gt;
&lt;li&gt;Real-world use cases with examples&lt;/li&gt;
&lt;li&gt;RabbitMQ vs Kafka — the honest comparison&lt;/li&gt;
&lt;li&gt;When to choose each&lt;/li&gt;
&lt;li&gt;Modern messaging alternatives worth knowing&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Do We Need Message Queues?
&lt;/h2&gt;

&lt;p&gt;Imagine an e-commerce app. When a customer places an order, multiple things need to happen:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Payment processing&lt;/li&gt;
&lt;li&gt;Inventory update&lt;/li&gt;
&lt;li&gt;Invoice generation&lt;/li&gt;
&lt;li&gt;Email notification&lt;/li&gt;
&lt;li&gt;Shipping workflow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;If everything happens synchronously:&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;User places order
  → API calls Payment Service (waits...)
    → API calls Inventory Service (waits...)
      → API calls Email Service (waits...)
        → Finally responds to user ❌ Slow. One failure = all fail.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;With RabbitMQ:&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;User places order
  → API publishes one event → returns instantly ✅
    → Payment Service processes independently
    → Inventory Service processes independently
    → Email Service processes independently
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The user gets an instant response. Each service works on its own. A crash in one doesn’t bring down the rest.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is RabbitMQ?
&lt;/h2&gt;

&lt;p&gt;RabbitMQ is an &lt;strong&gt;open-source message broker&lt;/strong&gt; that lets applications and microservices communicate asynchronously. It implements the &lt;strong&gt;AMQP (Advanced Message Queuing Protocol)&lt;/strong&gt; standard.&lt;/p&gt;

&lt;p&gt;Think of it as a post office:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Producer&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Writes and sends a message&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;RabbitMQ&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Stores and routes it reliably&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Consumer&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Receives and processes the message&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Services don’t talk directly to each other. They talk &lt;em&gt;through&lt;/em&gt; RabbitMQ. This decoupling is what gives you scalability, fault tolerance, and resilience.&lt;/p&gt;




&lt;h2&gt;
  
  
  How RabbitMQ Works Internally
&lt;/h2&gt;

&lt;p&gt;RabbitMQ has four core components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Producer → Exchange → Queue → Consumer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1. Producer
&lt;/h3&gt;

&lt;p&gt;The service that sends messages. Examples: Order Service, Payment Service, Notification Service.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Exchange
&lt;/h3&gt;

&lt;p&gt;The brain of RabbitMQ. It receives messages from producers and decides &lt;em&gt;where&lt;/em&gt; they go. There are four types:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🎯 Direct Exchange&lt;/strong&gt; — Routes by exact routing key match&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Message key: "order.created"

Exchange ──→ order.q    ✅ (exact match)
         ──→ payment.q  ❌ (no match)
         ──→ shipping.q ❌ (no match)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;📢 Fanout Exchange&lt;/strong&gt; — Broadcasts to ALL bound queues&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Message arrives

Exchange ──→ email.q    ✅
         ──→ sms.q      ✅
         ──→ push.q     ✅
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use case: notifications, cache invalidation, real-time updates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔍 Topic Exchange&lt;/strong&gt; — Wildcard pattern matching (&lt;code&gt;*&lt;/code&gt; = one word, &lt;code&gt;#&lt;/code&gt; = many)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Message key: "order.paid.india"

Exchange ──→ order.*    ❌ (* matches only one word)
         ──→ order.#    ✅ (# matches one or more)
         ──→ user.#     ❌ (wrong prefix)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Very common in microservices architectures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📋 Headers Exchange&lt;/strong&gt; — Routes by message header attributes instead of routing keys. Less common but powerful for complex filtering.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Queue
&lt;/h3&gt;

&lt;p&gt;Stores messages until a consumer is ready to process them. RabbitMQ guarantees delivery using acknowledgements, persistence, and retries.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Consumer
&lt;/h3&gt;

&lt;p&gt;The service that reads and processes messages. Consumers can scale horizontally — spin up more instances to handle high load.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real-World Example: Food Delivery App
&lt;/h2&gt;

&lt;p&gt;When someone places an order on a platform like Swiggy or Uber Eats:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Order API publishes one message:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"orderId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1001&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"restaurant"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Pizza Hub"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"customer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Saiyam"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"total"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;540.00&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;RabbitMQ fans it out to multiple queues:&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;Order API (Producer)
      │
   RabbitMQ Exchange
      │
      ├──→ 💳 Payment Queue     → charges the customer
      ├──→ 🍳 Restaurant Queue  → notifies the restaurant
      ├──→ 🛵 Delivery Queue    → assigns a delivery agent
      └──→ 🔔 Notification Queue → sends SMS/email
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each service works &lt;strong&gt;independently&lt;/strong&gt;. If the notification service crashes, payments still go through and orders still flow. Notifications retry automatically once it recovers.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;This isolation is RabbitMQ’s biggest strength.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Key Features of RabbitMQ
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Reliable Delivery&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Messages persist to disk — survive broker restarts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Acknowledgements&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Consumers confirm processing; unconfirmed messages are requeued&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Retry Mechanisms&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Failed messages retry automatically with configurable backoff&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Dead Letter Queues&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Unprocessable messages go to a DLQ for investigation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Priority Queues&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;High-priority tasks jump the queue&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Delayed Messaging&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Schedule retries, reminders, or deferred tasks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Horizontal Scaling&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Add more consumer instances to handle load&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  RabbitMQ vs Kafka
&lt;/h2&gt;

&lt;p&gt;This is the most common question in distributed systems. They look similar on the surface but solve fundamentally different problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The one-line mental model:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🐇 &lt;strong&gt;RabbitMQ&lt;/strong&gt; — &lt;em&gt;“Deliver this task reliably to someone who will act on it now.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;⚡ &lt;strong&gt;Kafka&lt;/strong&gt; — &lt;em&gt;“Persist and stream this event so anyone can consume it — now or in the future.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Full Comparison
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;🐇 RabbitMQ&lt;/th&gt;
&lt;th&gt;⚡ Kafka&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Primary purpose&lt;/td&gt;
&lt;td&gt;Message broker&lt;/td&gt;
&lt;td&gt;Event streaming platform&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Message model&lt;/td&gt;
&lt;td&gt;Queue-based&lt;/td&gt;
&lt;td&gt;Distributed log&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Throughput&lt;/td&gt;
&lt;td&gt;Moderate&lt;/td&gt;
&lt;td&gt;Extremely high (millions/s)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Latency&lt;/td&gt;
&lt;td&gt;Very low (&amp;lt; 1ms)&lt;/td&gt;
&lt;td&gt;Low (few ms)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Message retention&lt;/td&gt;
&lt;td&gt;Deleted after consumption&lt;/td&gt;
&lt;td&gt;Long-term (days/forever)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Replay messages&lt;/td&gt;
&lt;td&gt;Limited&lt;/td&gt;
&lt;td&gt;Excellent (seek to any offset)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Routing flexibility&lt;/td&gt;
&lt;td&gt;Very high (4 exchange types)&lt;/td&gt;
&lt;td&gt;Moderate (topic-based)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ordering&lt;/td&gt;
&lt;td&gt;Per-queue&lt;/td&gt;
&lt;td&gt;Per-partition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Task queues, workflows&lt;/td&gt;
&lt;td&gt;Streaming, analytics, pipelines&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  When RabbitMQ is the right choice
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Email / SMS / push notification pipelines&lt;/li&gt;
&lt;li&gt;Payment and order workflows&lt;/li&gt;
&lt;li&gt;Background job processing&lt;/li&gt;
&lt;li&gt;Microservice orchestration&lt;/li&gt;
&lt;li&gt;Any system needing complex routing logic&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When Kafka is the right choice
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Real-time analytics dashboards&lt;/li&gt;
&lt;li&gt;Data lake ingestion pipelines&lt;/li&gt;
&lt;li&gt;Clickstream and log aggregation&lt;/li&gt;
&lt;li&gt;IoT telemetry at massive scale&lt;/li&gt;
&lt;li&gt;Event sourcing and audit trails&lt;/li&gt;
&lt;li&gt;Fraud detection systems (e.g., Netflix, banking)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Can they work together?
&lt;/h3&gt;

&lt;p&gt;Absolutely. Many production architectures use both:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Operational layer   →  RabbitMQ  (process payments, send notifications)
Analytics layer     →  Kafka     (fraud detection, dashboards, audit logs)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Modern Messaging Technologies Worth Knowing
&lt;/h2&gt;

&lt;p&gt;The ecosystem is evolving. A few alternatives gaining real traction:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Apache Pulsar&lt;/strong&gt; — Combines RabbitMQ + Kafka capabilities in one system. Built cloud-native with multi-tenancy, geo-replication, and tiered storage. Many consider it a strong Kafka alternative.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NATS&lt;/strong&gt; — Lightweight and blazingly fast. Born for Kubernetes and edge computing. Zero complex configuration — just run it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redis Streams&lt;/strong&gt; — Event streaming built into Redis. If Redis is already in your stack, this adds streaming with zero new infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amazon SQS&lt;/strong&gt; — Fully managed by AWS. Best for teams who want zero infrastructure management. Less routing flexibility, but operationally effortless.&lt;/p&gt;




&lt;h2&gt;
  
  
  Which Should You Learn First?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Start with RabbitMQ if you:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Work with microservices or enterprise systems&lt;/li&gt;
&lt;li&gt;Build transactional workflows (payments, orders, notifications)&lt;/li&gt;
&lt;li&gt;Want something easier to operate and reason about&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Start with Kafka if you:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Work in big data, analytics, or data engineering&lt;/li&gt;
&lt;li&gt;Build streaming platforms or event-sourcing systems&lt;/li&gt;
&lt;li&gt;Work on large-scale distributed systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Knowing both is extremely valuable for senior backend engineers and architects.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;RabbitMQ remains one of the most reliable and practical messaging systems in modern software engineering. Its strengths — routing flexibility, operational stability, and battle-tested reliability — make it the preferred choice for business-critical workflows.&lt;/p&gt;

&lt;p&gt;Kafka dominates large-scale event streaming. But both tools have their place.&lt;/p&gt;

&lt;p&gt;The best engineers understand not just &lt;em&gt;how&lt;/em&gt; these technologies work, but &lt;em&gt;when&lt;/em&gt; to reach for each one. In distributed systems, &lt;strong&gt;choosing the right communication model matters more than choosing the trendiest technology&lt;/strong&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Have you used RabbitMQ or Kafka in production? Do you prefer NATS or Pulsar? Drop your experience in the comments — would love to hear real-world war stories.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rabbitmq</category>
      <category>kafka</category>
      <category>distributedsystems</category>
      <category>eventdriven</category>
    </item>
    <item>
      <title>Understanding SQL Ranking Functions: RANK, DENSE_RANK, and ROW_NUMBER</title>
      <dc:creator>Saiyam Jain</dc:creator>
      <pubDate>Thu, 25 Jul 2024 14:25:36 +0000</pubDate>
      <link>https://dev.to/cybersaiyam/understanding-sql-ranking-functions-rank-denserank-and-rownumber-6l5</link>
      <guid>https://dev.to/cybersaiyam/understanding-sql-ranking-functions-rank-denserank-and-rownumber-6l5</guid>
      <description>&lt;p&gt;In SQL, ranking functions are used to assign a rank or a sequential number to rows in a result set based on the values of one or more columns. These functions are particularly useful for tasks like sorting, ranking, and partitioning data. The most commonly used ranking functions are &lt;code&gt;RANK&lt;/code&gt;, &lt;code&gt;DENSE_RANK&lt;/code&gt;, and &lt;code&gt;ROW_NUMBER&lt;/code&gt;. This article explains these functions and demonstrates how to use them with SQL queries.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Concepts
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;RANK()&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Assigns a rank to each row within a result set based on the specified ordering. Rows with the same values receive the same rank, and subsequent ranks are adjusted to account for ties, resulting in gaps in the ranking sequence.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;: If two rows share the highest rank (1), the next rank assigned will be 3, leaving a gap.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;DENSE_RANK()&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Similar to &lt;code&gt;RANK&lt;/code&gt;, but without gaps in the ranking values. Rows with the same values receive the same rank, and the next distinct value gets the immediate next rank.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;: If two rows share the highest rank (1), the next rank assigned will be 2, without any gaps.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;ROW_NUMBER()&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Assigns a unique sequential integer to each row based on the specified ordering. It does not consider the values of the rows for ranking and does not create ties or gaps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;: Each row is given a unique number starting from 1, regardless of the values in the rows.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Practical Example
&lt;/h3&gt;

&lt;p&gt;Consider a table named &lt;code&gt;StudentMarks&lt;/code&gt; with the following data:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Marks&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;89&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;To apply these ranking functions, we need to order the data by the &lt;code&gt;Marks&lt;/code&gt; column in descending order.&lt;/p&gt;

&lt;h3&gt;
  
  
  SQL Queries
&lt;/h3&gt;

&lt;p&gt;Here’s how you can use &lt;code&gt;RANK&lt;/code&gt;, &lt;code&gt;DENSE_RANK&lt;/code&gt;, and &lt;code&gt;ROW_NUMBER&lt;/code&gt; functions in SQL to get the ranking of each row:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. &lt;code&gt;DENSE_RANK&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Marks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;DENSE_RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;Marks&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;DenseRank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;
    &lt;span class="n"&gt;StudentMarks&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
| Name | Marks | DenseRank |&lt;br&gt;
|------|-------|-----------|&lt;br&gt;
| A    | 100   | 1         |&lt;br&gt;
| B    | 100   | 1         |&lt;br&gt;
| C    | 89    | 2         |&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Explanation&lt;/strong&gt;: Both A and B have the highest marks (100) and share rank 1. The next distinct mark (89) gets rank 2.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. &lt;code&gt;RANK&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Marks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;Marks&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;Rank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;
    &lt;span class="n"&gt;StudentMarks&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
| Name | Marks | Rank |&lt;br&gt;
|------|-------|------|&lt;br&gt;
| A    | 100   | 1    |&lt;br&gt;
| B    | 100   | 1    |&lt;br&gt;
| C    | 89    | 3    |&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Explanation&lt;/strong&gt;: Both A and B share rank 1. The next distinct mark (89) receives rank 3, creating a gap because ranks 1 and 2 are taken.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. &lt;code&gt;ROW_NUMBER&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Marks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ROW_NUMBER&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;Marks&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;RowNumber&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;
    &lt;span class="n"&gt;StudentMarks&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
| Name | Marks | RowNumber |&lt;br&gt;
|------|-------|-----------|&lt;br&gt;
| A    | 100   | 1         |&lt;br&gt;
| B    | 100   | 2         |&lt;br&gt;
| C    | 89    | 3         |&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Explanation&lt;/strong&gt;: Each row is assigned a unique sequential number based on the descending order of marks. There are no ties or gaps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;SQL ranking functions such as &lt;code&gt;RANK&lt;/code&gt;, &lt;code&gt;DENSE_RANK&lt;/code&gt;, and &lt;code&gt;ROW_NUMBER&lt;/code&gt; are powerful tools for organizing and analyzing data. Understanding the differences between these functions allows you to choose the appropriate ranking method based on your needs, whether it’s handling ties, avoiding gaps, or simply numbering rows sequentially. By using these functions effectively, you can gain valuable insights and present data in a meaningful way.&lt;/p&gt;

</description>
      <category>advancesql</category>
      <category>programming</category>
      <category>database</category>
      <category>data</category>
    </item>
    <item>
      <title>5 ways to reverse a string in Python</title>
      <dc:creator>Saiyam Jain</dc:creator>
      <pubDate>Sun, 07 Nov 2021 19:10:30 +0000</pubDate>
      <link>https://dev.to/cybersaiyam/5-ways-to-reverse-a-string-in-python-4go8</link>
      <guid>https://dev.to/cybersaiyam/5-ways-to-reverse-a-string-in-python-4go8</guid>
      <description>&lt;p&gt;Hello everyone, in this post I will provide you 5 different ways to reverse a string using python programming.&lt;/p&gt;

&lt;h3&gt;
  
  
  1
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Using Slicing
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def StrRev(string):
    string = string[::-1]
    return string

s = input("Enter a string: ")

print (StrRev(s))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Using Reversed Function
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def StrRev(string):
    string = "".join(reversed(string))
    return string

s = input("Enter a string: ")
print (StrRev(s))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Using Loop
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def StrRev(s):
  strg = ""
  for i in s:
    strg = i + strg
  return strg

s = input("Enter a string: ")
print (StrRev(s))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Using Recursive function
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def StrRev(s):
    if len(s) == 0:
        return s
    else:
        return StrRev(s[1:]) + s[0]

s = input("Enter a string: ")
print(StrRev(s))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Using Stack Operations
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def StackCreate():
    stack=[]
    return stack


def isEmpty(stack):
    if len(stack) == 0:
        return true


def push(stack,item):
    stack.append(item)

def pop(stack):
    if isEmpty(stack): return
    return stack.pop()


def StrRev(string):
    n = len(string)


    stack = StackCreate()

    for i in range(0,n,1):
        push(stack,string[i])

    string=""

    for i in range(0,n,1):
        string+=pop(stack)

    return string

s = input("Enter a string: ")
print (StrRev(s))

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

&lt;/div&gt;



</description>
      <category>python</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
