RTUComputer ScienceYr 2026 · Sem 82026

Q20Big Data Analytics

Question

10 marks

Detail real-time analytics using Kafka and Spark.

Answer

A definitive architectural guide to Real-Time Analytics using Apache Kafka and Spark Streaming. Explains how Kafka's massive distributed log buffers the chaotic data tsunami, and how Spark's Micro-Batching mathematics violently processes the stream in sub-second intervals.

In the modern data architecture, processing data overnight is obsolete. If a credit card is stolen, the fraud must be mathematically detected in 50 milliseconds, not tomorrow morning. This requires a violently robust Real-Time Pipeline. The absolute industry standard for this architecture is the combination of Apache Kafka (the shock absorber) and Apache Spark Streaming (the mathematical engine).

If 10 million IoT devices suddenly spike and blast data simultaneously, they will mathematically crash any database. Apache Kafka sits at the front door to prevent this.

  • Architecture: Kafka is a massively distributed, append-only Commit Log. It does not process data; it just violently absorbs it and writes it directly to disk sequentially, allowing it to ingest millions of messages per second with zero lag.
  • Topics and Partitions: The data is mathematically categorized into "Topics". Each topic is physically chopped into "Partitions" spread across multiple servers. This guarantees catastrophic fault tolerance and allows hundreds of consumers to read the data completely in parallel.
  • Decoupling: Kafka completely decouples the producers (IoT devices) from the consumers (Spark). If Spark crashes and burns for 10 minutes, Kafka safely holds the data. When Spark reboots, it mathematically resumes reading from its exact last offset.

Spark reads the chaotic, infinite stream of bytes from Kafka and executes complex mathematical analytics.

  • Micro-Batch Architecture (DStreams): Traditional Spark operates on massive, static RDDs. Spark Streaming violently chops the infinite Kafka stream into tiny chunks based on time (e.g., exactly 0.5 seconds of data). This tiny chunk is converted into an RDD, and the standard Spark engine crushes it.
  • Structured Streaming: The modern evolution. It mathematically treats the infinite Kafka stream as an infinitely growing SQL table. The developer writes a standard SQL query (SELECT count(*) FROM stream GROUP BY ip_address), and Spark mathematically continuously updates the answer in RAM every millisecond.
  • Windowing Operations: Spark can execute complex mathematical analysis over time. E.g., "Calculate the average temperature over a sliding 10-minute window, updating every 2 seconds." It manages the chaotic out-of-order arrival of data using "Event-Time Watermarking".

1. A credit card is swiped at a terminal. 2. The terminal blasts the JSON payload into a Kafka Topic. 3. Spark Streaming instantly pulls the JSON, parses it, and feeds it into a pre-trained Machine Learning Random Forest model residing in RAM. 4. The model mathematically predicts a 99% probability of fraud. 5. Spark instantly fires a command back to the banking API to physically decline the transaction, executing the entire architectural loop in under 50 milliseconds.

Back to Paper