1. Home
  2. Explore
  3. Computer Science
  4. Big Data Analytics Overview

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Big Data Analytics Overview

Big Data Analytics Study Notes

Introduction to Big Data

Big Data refers to vast volumes of data that cannot be processed using traditional database and data‑processing tools. The key challenges are scalability, processing speed, and the ability to handle diverse data types.

  • Traditional RDBMS systems (e.g., Oracle, MySQL) struggle when data grows beyond terabytes: queries become slow, joins over huge tables are impractical, and they cannot efficiently process unstructured data (images, audio, logs).

  • Unstructured data (JSON, log files, social media feeds) requires specialized storage and processing.

  • Examples of big data scenarios:

    • E‑commerce (Flipkart, Amazon): tracking user clicks, product views, purchases.

    • Banking (ICICI Bank): core banking data, CRM data, social media interactions, call logs.

    • Sensor data (GE aircraft engines): each engine generates ~1 TB of sensor data per flight.

Big Data is defined as data that cannot be processed using traditional methods due to its volume, velocity, or variety.

To handle such data, organizations use a combination of NoSQL databases (MongoDB, Cassandra) for real‑time operations and Hadoop for batch storage and processing.


Traditional Data Warehousing and ETL

ETL Process

  • Extract, Transform, Load: data is pulled from various sources (RDBMS, flat files, APIs), cleaned/transformed, and loaded into a central data warehouse.

  • The data warehouse is an OLAP (Online Analytical Processing) system – not customer‑facing; used for reporting and analytics.

  • Common ETL tools: Informatica, Talend, SSIS.

Limitations of Traditional Data Warehousing

  • Scalability: Data warehouse appliances are expensive and limited in capacity.

  • Batch‑oriented: ETL jobs typically run nightly; not real‑time.

  • Schema‑on‑write: Data must be structured before loading; changes are difficult.

  • Cost: High license and support fees (e.g., Teradata, Oracle).

For modern big data needs (real‑time recommendations, fraud detection, high‑volume streaming), Hadoop and its ecosystem provide a cheaper, more scalable alternative.


Hadoop Overview

  • Hadoop is an open‑source framework for distributed storage and processing of large datasets across clusters of commodity hardware.

  • Originally created by Doug Cutting and Mike Cafarella, inspired by Google’s MapReduce and GFS papers. Became an Apache project in 2006.

  • Commodity hardware: Use cheap, off‑the‑shelf servers instead of expensive enterprise machines. Failures are expected and handled by the software.

Core Components

  1. HDFS – Hadoop Distributed File System (storage)

  2. YARN – Yet Another Resource Negotiator (resource management and job scheduling)

  3. MapReduce – Original batch processing framework (now largely replaced by Spark)

Major Distributions

  • Cloudera – Commercial distribution with proprietary enhancements (e.g., Impala, Sentry).

  • Hortonworks – 100% open‑source (now part of Cloudera after merger). Uses Tez, Ranger.

  • MapR – High‑performance, but with different architecture.

  • Most cloud providers (AWS EMR, Azure HDInsight, Google Dataproc) offer managed Hadoop clusters.


HDFS – Hadoop Distributed File System

Architecture

  • NameNode (master): Stores metadata (file names, block locations, permissions). Runs on a dedicated machine.

  • DataNodes (slaves): Store the actual data blocks. Each DataNode sends heartbeats to the NameNode.

  • Secondary NameNode / Standby NameNode: Provides high availability (HA) via active‑standby configuration, using ZooKeeper for coordination.

Key Properties

  • Block size: Default 128 MB (configurable). Files are split into blocks and distributed across DataNodes.

  • Replication: Default replication factor = 3. Each block is replicated on three different DataNodes (ideally on different racks for fault tolerance).

  • Write‑once, read‑many: Files cannot be edited after creation. Only append is possible. This simplifies consistency.

  • Rack awareness: HDFS can be configured to place replicas across different racks to survive rack‑level failures.

  • Data locality: Processing frameworks (MapReduce, Spark) try to move computation to where the data resides to minimize network transfers.

How HDFS Works (Example)

  • Suppose a 192 MB file with block size 64 MB (older default). HDFS splits it into three blocks (64 MB, 64 MB, 64 MB).

  • The client contacts the NameNode to get DataNode addresses for each block.

  • Blocks are written in parallel; each block’s replicas are pipelined to other DataNodes.

  • NameNode stores metadata mapping file → blocks → DataNodes.

  • During read, the client queries the NameNode and then reads from the nearest DataNode containing a replica.

Failures and Recovery

  • If a DataNode fails, the NameNode detects the absence of heartbeats and replicates the missing blocks from other replicas.

  • If the NameNode fails, the standby NameNode takes over (requires shared edit logs, often via Quorum Journal Manager).

  • Re‑balancing: An administrator can run the hdfs balancer to redistribute blocks evenly across DataNodes.


Hadoop Ecosystem Tools

Data Ingestion

  • Sqoop: Transfers data between RDBMS (Oracle, MySQL) and HDFS. Used for batch imports/exports.

  • Flume: Reliable, configurable agent for collecting streaming log files and sending them to HDFS.

  • Kafka: Distributed, fault‑tolerant message queue. Producers publish data, consumers pull. Kafka acts as a buffer between data sources and processing frameworks (Spark Streaming, Flink).

Processing Frameworks

  • MapReduce: Original batch processing model – mapper, shuffle/sort, reducer. Slow due to disk I/O at each stage.

  • Spark: In‑memory cluster computing engine (see dedicated section below). Can run on YARN, Mesos, or standalone.

  • Flink: True real‑time stream processing (both streaming and batch).

  • Storm: Low‑latency stream processing (largely superseded by Flink and Spark Streaming).

SQL‑on‑Hadoop

  • Hive: HQL (SQL‑like) that translates to MapReduce/Tez/Spark jobs. Good for batch ETL.

  • Impala: Cloudera’s MPP SQL engine – low latency, in‑memory execution, but less fault‑tolerant.

  • Presto: Facebook’s distributed SQL query engine.

  • Drill: Schema‑free SQL for nested data.

  • HAWQ (now ELAP): Hortonworks’ enhanced Hive with ACID and near‑real‑time capabilities.

NoSQL on Hadoop

  • HBase: Column‑oriented NoSQL database on HDFS. Supports random reads/writes, but not SQL natively.

  • Phoenix: SQL skin for HBase – allows SQL queries against HBase tables.

  • Cassandra: Often used alongside Hadoop for real‑time operations (not HDFS based).

Workflow and Security

  • Oozie: Scheduler for Hadoop jobs (MapReduce, Pig, Hive, Spark).

  • Sentry (Cloudera) / Ranger (Hortonworks): Role‑based access control for HDFS, Hive, Impala, etc.

  • ZooKeeper: Coordination service for distributed systems (leader election, configuration management).


Hive – Data Warehouse on Hadoop

Overview

  • Hive provides a SQL‑like interface (HQL) to query data stored in HDFS.

  • Originally developed by Facebook to allow SQL developers to analyze big data without writing MapReduce.

  • HQL queries are compiled into MapReduce (or Tez/Spark) jobs that run on the cluster.

  • Schema‑on‑read: Data is not validated during load; schema is applied at query time.

Architecture

  • HiveServer2: Thrift service that accepts client connections (CLI, JDBC/ODBC).

  • MetaStore: Stores metadata (table definitions, column types, partition info). Typically uses a relational database (MySQL, PostgreSQL).

  • Driver: Compiles HQL, creates an execution plan, and launches MapReduce/Tez/Spark jobs.

  • Execution engine: Can be MapReduce, Tez, or Spark (configurable).

  • Hive on Tez (Hortonworks) – faster than MapReduce, uses DAG execution.

  • Hive on Spark – still experimental, but possible.

Managed vs External Tables

  • Managed table: Hive manages the data. When table is dropped, data is deleted. Data resides in the Hive warehouse directory (/user/hive/warehouse/).

  • External table: Data is stored outside the warehouse (e.g., in a custom HDFS path). Dropping the table only removes metadata; data remains.

Partitioning

  • Purpose: Improve query performance by splitting data into sub‑directories based on one or more columns (e.g., country, date).

  • Partition elimination: Queries with WHERE on partition columns only scan relevant directories.

  • Static partitioning: You manually specify the partition values when loading data.

  • Dynamic partitioning: Hive automatically creates partitions based on column values (must be enabled, with limits on number of partitions).

  • Best practice: Partition on low‑cardinality columns. Too many partitions can degrade NameNode performance.

Bucketing

  • Further sub‑divides partitions (or whole table) into a fixed number of files (buckets) using a hash of the bucketing column.

  • Useful for efficient bucket map joins when two tables are bucketed on the same join key.

  • Bucketing can improve sampling and reduce skew.

File Formats

  • TextFile: Plain text (CSV, JSON). No compression, no indexing.

  • SequenceFile: Binary key‑value pairs (Hadoop native, splittable).

  • ORC (Optimized Row Columnar): Columnar storage, high compression (zlib, snappy), built‑in indexes, vectorized reads (process batches of rows). Supports ACID in Hive 3.x.

  • Parquet: Columnar, efficient storage for nested data. Used by Spark, Impala.

  • Avro: Row‑oriented, schema‑embedded (good for serialization and schema evolution).

HiveQL Examples (from lecture)

-- Create managed table
CREATE TABLE transactions (
  trans_id INT,
  trans_date STRING,
  cust_id STRING,
  amount DOUBLE,
  category STRING,
  product STRING,
  state STRING,
  payment STRING
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

-- Load data from local file
LOAD DATA LOCAL INPATH '/path/to/file.txt' INTO TABLE transactions;

-- Create external table pointing to existing HDFS data
CREATE EXTERNAL TABLE logs (
  host STRING, identity STRING, user_id STRING, time STRING,
  request STRING, status INT, size INT
) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
  "input.regex" = "^(\\S+) (\\S+) (\\S+) \\[(.*?)\\] \"(.*?)\" (\\d+) (\\d+)$"
)
STORED AS TEXTFILE
LOCATION '/gl_data/access';

-- Partitioning example
CREATE TABLE user_part (
  first_name STRING, last_name STRING, id INT
) PARTITIONED BY (country STRING, region STRING);

-- Static partition load
LOAD DATA LOCAL INPATH 'users.txt' INTO TABLE user_part
PARTITION (country='New Zealand', region='Kiwi');

-- Dynamic partitioning (must be enabled)
SET hive.exec.dynamic.partition = true;
SET hive.exec.dynamic.partition.mode = nonstrict;
INSERT INTO user_part PARTITION(country, region)
SELECT first_name, last_name, id, country, region FROM temp_table;

-- Bucketing
SET hive.enforce.bucketing = true;
CREATE TABLE bucketed_table (
  price DOUBLE, bedrooms INT, ...
) CLUSTERED BY (street) INTO 4 BUCKETS;

-- Join query for analysis (e.g., total spend by age group)
INSERT INTO output_table
SELECT c.cust_id, c.first_name, c.age, t.amount, t.product
FROM customers c
JOIN transactions t ON c.cust_id = t.cust_id;

Performance Considerations

  • Use ORC with vectorization and predicate pushdown.

  • Enable Cost‑Based Optimizer (CBO) for better join ordering.

  • Partition and bucket appropriately.

  • Avoid full table scans on high‑cardinality columns.

  • Hive is batch oriented – not suitable for low‑latency queries. Use Impala or Spark SQL for interactive analysis.


Spark – Unified Analytics Engine

Why Spark?

  • Speed: In‑memory processing (up to 100x faster than MapReduce). Intermediate results stay in RAM.

  • Unified: Single engine for batch, streaming, SQL, machine learning, and graph processing.

  • Ease of use: High‑level APIs in Scala, Java, Python, R, and SQL.

  • Replaces: MapReduce, Storm, Mahout, and to some extent Hive (using Spark SQL).

History

  • Originated as a research project (Mesos) at UC Berkeley AMPLab (2009).

  • Spark was designed to test Mesos; later became its own project.

  • Became an Apache top‑level project in 2014.

  • Major versions: 1.x (RDD‑centric), 2.x (DataFrame/Dataset, SQL, structured streaming).

  • Databricks founded by the original Spark creators.

Architecture

  • Driver program: Contains the SparkContext (or SparkSession). Runs the main function and creates DAG of tasks.

  • Cluster manager: YARN, Mesos, Kubernetes, or Spark standalone. Allocates resources.

  • Executors: Worker processes that run tasks and store data for cached RDDs.

  • SparkSession: Entry point (replaces SparkContext in 2.x).

Deployment Modes

  • Local mode: Single JVM (driver + executors in one process). For testing/learning.

  • Standalone mode: Spark’s own cluster manager.

  • YARN mode: Most common in Hadoop clusters. Options: yarn-client (driver runs locally) or yarn-cluster (driver runs on cluster).

  • Kubernetes: Container‑orchestrated clusters.

RDD – Resilient Distributed Dataset

  • RDD is the core abstraction. An immutable, partitioned collection of records that can be processed in parallel.

  • Creation: From HDFS (textFile, sequenceFile), parallelizing collections, or transforming other RDDs.

  • Operations:

    • Transformations (lazy): map, filter, flatMap, reduceByKey, groupByKey, sortByKey, union, join, coalesce, repartition.

    • Actions (trigger execution): count, collect, take, reduce, saveAsTextFile, foreach.

  • Lazy evaluation: Computation is deferred until an action is called. Sparks builds a DAG of stages.

  • Caching/Persistence: rdd.cache() or rdd.persist(StorageLevel.MEMORY_AND_DISK) to keep RDD in memory across actions.

Spark SQL and DataFrames

  • DataFrame: A distributed collection of rows with a schema (like a table). More optimized than RDD due to Catalyst optimizer.

  • Dataset: Type‑safe API available in Scala/Java.

  • Spark SQL: Can query Hive tables, JSON files, Parquet, JDBC sources.

  • Optimization: Catalyst optimizer performs predicate pushdown, column pruning, and code generation (Tungsten).

Libraries

  • MLlib: Scalable machine learning (classification, regression, clustering, collaborative filtering).

  • GraphX: Graph processing (vertices, edges, algorithms like PageRank).

  • Spark Streaming: Micro‑batch stream processing. Can consume from Kafka, Flume, Kinesis, etc.

Spark Monitoring

  • Spark UI: Provides information on jobs, stages, tasks, executors, storage, environment, and SQL queries.

  • Available on port 4040 (or configured port) during application runtime. History server for completed applications.

Running Spark (Example)

# Start PySpark shell with 3 executors, each 2 GB memory, using YARN
pyspark --master yarn --num-executors 3 --executor-memory 2g
# Inside PySpark shell
text_file = spark.sparkContext.textFile("hdfs://.../file.txt")
errors = text_file.filter(lambda line: "ERROR" in line)
print(errors.count())          # Action: triggers execution
errors.saveAsTextFile("hdfs://path/errors")

Key Differences from MapReduce

  • In‑memory processing: No constant disk I/O between map and reduce phases.

  • Rich API: More operators than just map/reduce.

  • Lazy evaluation: Optimizer can reorder operations.

  • Fault tolerance: Lineage graph allows recomputation of lost partitions.

  • Interactive shell: Facilitates exploration.


Practical Demonstrations and Best Practices

Hive with ORC

  • Create table with STORED AS ORC for better compression and performance.

  • Example: CREATE TABLE sales_orc STORED AS ORC AS SELECT * FROM sales_text;

  • Set properties: set hive.vectorized.execution.enabled=true; for batch row processing.

Spark Tuning

  • Number of partitions: A good rule of thumb is 2–3 tasks per CPU core.

  • Executor memory: Leave 10–20% overhead for JVM and system processes.

  • Dynamic allocation: Let Spark request/release executors based on workload.

  • Caching: Persist RDDs/DataFrames that are reused multiple times.

  • Shuffle: Minimise shuffles (reduceByKey vs groupByKey).

Monitoring

  • Use the Spark History Server (port 18080 typically) to view completed applications.

  • In Hive, enable hive.exec.dynamic.partition.mode=nonstrict cautiously to avoid creating too many partitions.


Conclusion

This tutorial covered the fundamental concepts of Big Data, the Hadoop ecosystem, Hive for data warehousing, and Spark as a unified analytics engine. Understanding these technologies is essential for anyone entering the field of data engineering or data science. The next step is hands‑on practice with real datasets to solidify these concepts.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent