Sunday, 23 August 2026

Distributed Consensus - Paxos

 

Distributed Consensus — Class Notes

1. What Is Distributed Consensus?

Distributed consensus is the problem of getting multiple computers/nodes to agree on a value or state, even though:

  • Nodes operate concurrently.

  • Nodes communicate asynchronously.

  • Nodes can fail unpredictably.

  • The nodes are maintaining some mutable state.

This is essentially the same distributed-system environment we've been studying: concurrent + asynchronous + failure-prone processes.

The lecture focuses on Paxos as the consensus protocol.


2. Why Do We Need Consensus?

Imagine three replicas holding some mutable value:

Node A → Red
Node B → Red
Node C → Blue

The system needs to determine:

What value should everyone agree on?

We can't simply assume that one node is always correct because:

  • A node might be down.

  • A message might be delayed.

  • A message might never arrive.

  • Different nodes might have different information.

Therefore, we need a formal protocol for reaching agreement.


3. Four Requirements of Consensus

A consensus algorithm has four important properties.

① Termination

The process must eventually reach a decision.

In simple terms:

Don't wait forever.

Eventually, the system should decide on a value.

Proposal
   ↓
Consensus process
   ↓
Decision

If the algorithm never decides, it isn't useful.


4. Validity

The chosen value must be a value that was actually proposed.

Suppose:

Node A → proposes Red
Node B → proposes Blue
Node C → proposes Green

The consensus algorithm cannot suddenly decide:

Yellow

because nobody proposed Yellow.

So:

The decided value must come from a proposal.

The transcript describes this as integrity/validity: a process cannot simply invent the decided value.


5. Integrity

The lecture separates the formal requirements into:

Termination
Validity
Integrity
Agreement

Integrity means that if a process decides on a value, that value must have been proposed by some process.

So:

Proposed:
A → Red
B → Blue
C → Green

Allowed:
Red / Blue / Green

Not allowed:
Yellow

6. Agreement

Eventually, the processes must agree on the same value.

For example:

Node A → Red
Node B → Red
Node C → Red

Not:

Node A → Red
Node B → Blue
Node C → Green

The objective is:

All participating processes eventually reach the same decision.


7. Four Properties — Easy Memory

Remember:

PropertySimple Meaning
TerminationEventually decide
ValidityDecide a proposed value
IntegrityDon't invent a value
AgreementEveryone agrees

🧠 Memory trick

TVIA

Terminate → Valid value → Integrity → Agreement


8. What Is Paxos?

Paxos is a deterministic, fault-tolerant distributed consensus protocol.

Its purpose is to help nodes agree despite node failures and unreliable communication.

The lecture uses Paxos particularly in the context of replicated durable mutable state, such as databases.

The key idea is:

Multiple nodes
      ↓
Different information / failures
      ↓
Paxos protocol
      ↓
Consistent decision

9. Paxos and Replicated Databases

Imagine we have three replicas:

       Client
      /   |   \
     ↓    ↓    ↓
   Node A Node B Node C

Suppose we're storing some mutable value.

The replicas need to agree on the value.

Paxos helps establish a consistent result despite failures.

The lecture specifically connects this idea with Cassandra's lightweight transactions, where the nodes involved in the operation use Paxos-style consensus.


10. Important: Paxos Doesn't Always Make Progress

This is a very important distinction.

Paxos can guarantee a consistent result, but there can be situations where it cannot make progress.

In other words:

It is better to report failure than to return an incorrect answer.

For example, if there isn't enough information/participation to establish consensus, the system should say:

CONSENSUS FAILED

rather than:

Here is a value...

when that value isn't reliable.


11. Quorum — The Key Concept in This Example

The lecture then introduces a simple read example.

Suppose we have:

Client
   |
   +---------+---------+
   ↓         ↓         ↓
Replica A  Replica B  Replica C

The client reads from all three replicas.

Suppose all three return:

A → Restrepo
B → Restrepo
C → Restrepo

Then the system sees:

Restrepo
Restrepo
Restrepo

Clearly there is agreement.

So the client can return:

Restrepo

12. What If One Replica Disagrees?

Suppose we get:

A → Restrepo
B → Restrepo
C → Skinny

We have:

Restrepo = 2
Skinny   = 1

There is still a quorum for Restrepo.

Therefore:

Result → Restrepo

The important concept is:

A majority/quorum agrees on Restrepo.


13. What If There Is No Quorum?

Now suppose:

A → Restrepo
B → Skinny
C → Skinny

Actually, here Skinny still has a majority of 2, so Skinny would be the quorum result.

The failure case described in the lecture is when there is no quorum.

For example, with three replicas:

A → Restrepo
B → Skinny
C → another value

There is no majority.

Therefore:

No quorum
    ↓
No consensus
    ↓
Read fails

The system does not simply guess.

The lecture's key point is:

If there is no quorum, return a failure rather than return a potentially incorrect answer.


14. Why Quorum Matters

With three replicas:

        3 replicas
       /    |    \
      A     B     C

A majority is:

2 out of 3

So:

2 → Restrepo
1 → Skinny

means:

Consensus → Restrepo

But:

1 → Restrepo
1 → Skinny
1 → Something else

means:

No majority
     ↓
No consensus
     ↓
Failure

15. Happy Path vs Failure Path

Happy path

Client
  ↓
A → Restrepo
B → Restrepo
C → Restrepo
  ↓
Consensus
  ↓
Restrepo

Slightly imperfect but still successful

Client
  ↓
A → Restrepo
B → Restrepo
C → Skinny
  ↓
2/3 = quorum
  ↓
Restrepo

Failure

Client
  ↓
A → Restrepo
B → Skinny
C → Other
  ↓
No quorum
  ↓
FAIL

⭐ Big Picture: Where Paxos Fits

Connect this with the previous topics you've studied:

Distributed System
        ↓
No global clock
        ↓
        ├── NTP
        │    └── Approximate physical time
        │
        └── Vector Clock
             └── Event ordering / causality

Then:
        
Multiple nodes need to AGREE
        ↓
Distributed Consensus
        ↓
Paxos
        ↓
Agreement despite failures

🧠 One-line memory trick

Vector Clock tells us "what happened before what"; Paxos helps nodes decide "what should we all agree on."

And for the Paxos section, remember the four requirements:

Termination + Validity + Integrity + Agreement

and the practical rule:

If the system cannot establish a reliable quorum/consensus, fail rather than return a wrong answer.


---


paxos write:

Paxos — Class Notes

1. What is Paxos?

Paxos is a distributed consensus protocol used to help multiple distributed nodes agree on a value, even when nodes can fail or messages can be delayed.

A typical example:

Several database replicas need to agree that the value of a key should be "Flat White".

Paxos ensures that once a value is chosen, conflicting values cannot both become the agreed-upon value.


2. Paxos Happy Path

Even when everything works correctly, Paxos involves several communication steps between nodes.

Assume we have:

  • 1 Proposer

  • Several Acceptors

  • A replicated key/value

  • Value = Flat White

The basic process has four phases:

  1. Prepare

  2. Promise

  3. Accept Request

  4. Acceptance


Phase 1 — Prepare

The client asks a node to write:

Key: Coffee
Value: Flat White

The node handling the request becomes the Proposer.

The Proposer generates a sequence number / proposal number.

Example:

Proposal Number = 1
Value = Flat White

The proposal is sent to the other replicas, which act as Acceptors.

Important property of proposal numbers

The proposal number must be:

  • Unique across the cluster

  • Sortable / comparable

For example, it could contain:

Timestamp + Node ID + Random component

The important point is that proposals must be unambiguously ordered.

The proposal number is a distributed ordering mechanism, not a distributed counter.


Phase 2 — Promise

The replicas receiving the proposal become Acceptors.

Suppose the proposal is:

Proposal = 1
Value = Flat White

Each Acceptor checks the proposal number against the highest proposal number it has already seen for that key.

Rule

An Acceptor promises:

"I will not accept a future proposal with a number lower than this proposal number."

So if the Acceptor receives proposal 2000, it promises:

I will not accept proposals < 2000

Important:

Promise does NOT mean:

"I promise to accept proposal 2000."

It means:

"I promise not to accept anything lower than 2000."


What does the Acceptor send back?

The Acceptor returns information about:

  • The proposal number it is promising

  • Any previously accepted proposal/value, if applicable

On the happy path, suppose all nodes have nothing better to report.

They return:

Proposal = 1
Value = Flat White

The Proposer receives a quorum of responses.


What is a Quorum?

A quorum is enough nodes to establish agreement/progress.

For example, with 5 replicas:

5 nodes
↓
Need majority
↓
3 nodes = quorum

Paxos does not necessarily need unanimous agreement.

It needs a sufficient quorum.

This is critical because some nodes may be unavailable.


Phase 3 — Accept Request

After receiving a quorum of promises, the Proposer sends an Accept Request.

Example:

Proposal Number = 1
Value = Flat White

The Acceptors check again:

"Has anyone presented a higher proposal since I made my promise?"

If no higher proposal has appeared, they accept:

1 → Flat White

Phase 4 — Acceptance

The Acceptors confirm the proposal.

Once the Proposer has the required quorum of acceptances:

Proposal 1
Value = Flat White

is considered successfully chosen.

The Proposer can then tell the client:

WRITE SUCCESS

Paxos Happy Path — Easy Diagram

Client
  |
  | Write: Flat White
  v
Proposer
  |
  | Prepare(1)
  +---------------------> Acceptor 1
  |                       Promise(1)
  |
  +---------------------> Acceptor 2
  |                       Promise(1)
  |
  +---------------------> Acceptor 3
                          Promise(1)

       <---- Quorum of Promises ----

Proposer
  |
  | Accept(1, Flat White)
  +---------------------> Acceptor 1
  |                       Accepted
  |
  +---------------------> Acceptor 2
  |                       Accepted
  |
  +---------------------> Acceptor 3
                          Accepted

       <---- Quorum of Acceptances ----

Proposer
  |
  v
Client
WRITE SUCCESS

3. Important Paxos Scenario — A Better Proposal Appears

Now consider a more interesting situation.

The Proposer starts with:

Proposal 5
Value = Cafe Cubano

It sends:

Prepare(5)

But one Acceptor has already seen a higher proposal:

Proposal 8
Value = French Press

Therefore, that Acceptor cannot simply promise proposal 5.

It responds with the information about the higher proposal:

Highest proposal = 8
Value = French Press

What does the Proposer do?

The Proposer realizes:

"There is already a higher proposal that I need to respect."

Therefore, instead of continuing with:

5 → Cafe Cubano

it changes its proposal to:

8 → French Press

The other Acceptors may initially have been happy with:

5 → Cafe Cubano

but they had promised not to accept proposals below 5.

Proposal 8 is greater than 5.

Therefore:

8 > 5

So accepting proposal 8 is allowed.

The result becomes:

8 → French Press

4. Key Paxos Rule

The most important idea to remember:

Higher proposal numbers override lower proposal numbers.

Example:

Proposal 5 → Cafe Cubano
Proposal 8 → French Press

Because:

8 > 5

the higher proposal wins.

This mechanism allows Paxos to deal with competing proposals.


5. What Happens During Failures?

The happy path is relatively straightforward.

The difficult part of Paxos comes from scenarios such as:

  • Proposer failure

  • Acceptor failure

  • Network delays

  • Message loss

  • Multiple competing proposers

  • Two proposers making proposals simultaneously

  • A higher proposal appearing halfway through the protocol

These situations can produce complicated protocol/message diagrams.

However, Paxos is designed so that these scenarios still preserve consistency and agreement.


6. Paxos Roles

Remember these three terms:

Proposer

The node that proposes a value.

Client
  ↓
Proposer

Acceptor

Nodes that participate in deciding whether a proposal can be accepted.

Proposer
   ↓
Acceptors

Learner

A node/process that learns the final chosen value.

Depending on the implementation, roles can sometimes be combined.


7. Paxos as a Form of Distributed Master Election

Paxos can also be used to elect a master.

Imagine every node writes its own name:

Node A → "A"
Node B → "B"
Node C → "C"

If a node successfully establishes its value through consensus, it can become the master.

Conceptually:

Paxos
  ↓
Agreement
  ↓
One chosen value
  ↓
Master election

So Paxos can be viewed as a mechanism for achieving agreement on who/what should be selected.


8. Paxos vs Raft

Paxos

  • Distributed consensus protocol

  • Powerful but complicated

  • Failure scenarios can be difficult to reason about

  • Historically important and widely influential

Raft

Raft performs essentially the same fundamental job:

Distributed consensus.

But Raft was specifically designed to be easier to understand and implement.

A useful interview comparison:

PaxosRaft
Consensus protocolConsensus protocol
More difficult to understandDesigned for understandability
Complex failure scenariosMore structured approach
Historically influentialEasier to implement
Used as foundation in distributed systemsUsed in many distributed systems

9. Paxos vs Blockchain Consensus

Traditional Paxos assumes something important:

Nodes are generally non-malicious.

They may:

  • crash

  • become unavailable

  • experience network problems

But they are not deliberately trying to deceive the system.

Blockchain consensus is designed for a different environment where participants may be Byzantine/malicious.

For example:

Paxos
↓
Crash / failure tolerance
↓
Nodes generally cooperate

Whereas:

Blockchain / Byzantine consensus
↓
Some participants may lie
↓
System must still reach agreement

Bitcoin's consensus mechanism is therefore fundamentally different from ordinary crash-fault-tolerant consensus such as Paxos.


10. Paxos in Cassandra

A practical example is Cassandra Lightweight Transactions (LWT).

LWT provides conditional operations such as:

INSERT ... IF NOT EXISTS

Example:

Create username = "ramesh"
IF NOT EXISTS

Suppose two users simultaneously try to register:

User A → ramesh
User B → ramesh

Without coordination, both could potentially believe they succeeded.

Paxos-based coordination allows the system to establish:

ramesh → User A

and reject the conflicting operation.

Important distinction

Cassandra LWT is not the same as a traditional full database transaction such as:

BEGIN
   UPDATE...
   UPDATE...
   UPDATE...
COMMIT

Instead, it provides conditional/linearizable operations, typically within the relevant Cassandra partition.


11. Other Uses of Paxos

Paxos-style consensus can be used for:

  • Leader/master election

  • Distributed locking

  • Distributed transaction coordination

  • Replicated state machines

  • Metadata agreement

  • Coordination services

Examples mentioned in the lecture include systems such as:

  • Cassandra Lightweight Transactions

  • ClusterX-style distributed relational systems

  • Google's Chubby coordination/lock service


12. The Most Important Concepts to Remember

1. Proposal number

Every proposal gets a unique, orderable number.

5 < 8 < 12

2. Prepare

Proposer asks:

"Will you promise not to accept anything below my proposal number?"

3. Promise

Acceptor says:

"I will not accept a lower proposal."

It does not necessarily mean it promises to accept the current proposal.

4. Quorum

The Proposer needs enough responses to make progress.

Majority / quorum

5. Accept Request

The Proposer asks Acceptors to accept the proposal/value.

6. Higher proposal wins

If an Acceptor has already seen a higher proposal, the lower proposal must yield.

7. Consensus

The final goal is:

Multiple nodes
      ↓
Agreement
      ↓
One consistent decision

13. Paxos in One-Line Interview Definition

Paxos is a distributed consensus protocol that enables a group of nodes to agree on a value despite node failures and unreliable communication, using ordered proposal numbers, promises, acceptances, and quorums.


🧠 Remember Paxos with this flow

CLIENT
   ↓
PROPOSER
   ↓
PREPARE
   ↓
PROMISE
   ↓
QUORUM
   ↓
ACCEPT REQUEST
   ↓
ACCEPTORS ACCEPT
   ↓
QUORUM
   ↓
VALUE CHOSEN

The golden rule:

Prepare → Promise → Accept → Accepted

And:

Higher proposal number always takes precedence over a lower proposal number. 

Distributed Synchronization -

 

Distributed Synchronization — Class Notes

1. Why Synchronization Is Difficult

A distributed system has three important characteristics:

  1. Concurrent operation — multiple nodes perform computations at the same time.

  2. Independent failures — one node can fail without telling us anything about when another node will fail.

  3. No shared/global clock — there is no single clock that all nodes can rely on as the exact same source of time.

The third point creates a major challenge.

In a distributed system, we cannot guarantee that:

“All nodes agree that it is exactly the same moment.”

We can synchronize clocks approximately, but perfect synchronization is practically impossible.


2. Why Does “Now” Matter?

Consider a distributed data store with replicated data.

Suppose we have three replicas:

ReplicaValue
Node 1Americano
Node 2Americano
Node 3Bread

Now the replicas disagree.

The important question is:

Which value was written last?

Without knowing the order of writes, we cannot confidently decide which value should win.

For example:

Write 1 → Americano
Write 2 → Bread

or perhaps:

Write 1 → Bread
Write 2 → Americano

Looking only at the current replica values doesn't tell us which happened last.


3. Solution #1 — Timestamps

One approach is to attach a timestamp to every write.

Example:

Americano → 10:01:05
Bread     → 10:01:08

The system can then use:

Last Write Wins (LWW)

So the value with the latest timestamp becomes the winner.

Advantage

Very simple and works well in many real-world distributed systems.

Problem

It depends on having reasonably accurate clocks across nodes.

If Node A's clock says:

10:01:10

while Node B's clock says:

10:01:05

the timestamps may produce the wrong ordering.

Therefore, the question becomes:

How accurate does our clock synchronization need to be?


4. How Do We Synchronize Clocks?

Option 1 — GPS

We could install GPS receivers on servers and use GPS time as a common reference.

Conceptually:

        GPS Time
           ↓
   ┌───────┼───────┐
   ↓       ↓       ↓
 Node A  Node B  Node C

This can provide extremely accurate time.

However, for most distributed systems, it is:

  • expensive

  • complicated

  • unnecessary

  • difficult to deploy at large scale

So it is usually impractical.


5. NTP — Network Time Protocol

The common solution is Network Time Protocol (NTP).

NTP allows computers to synchronize their clocks over a network using reliable time sources.

Conceptually:

       Time Server
            ↓
     ┌──────┼──────┐
     ↓      ↓      ↓
   Node A Node B Node C

NTP doesn't make every machine's clock perfectly identical.

Instead, it gets the clocks close enough for many practical applications.

Key idea

NTP gives us an estimate of physical time.

This is often sufficient for systems that use timestamps and Last Write Wins.


6. What If “Good Enough” Isn't Good Enough?

This is where things become interesting.

Suppose our application requires extremely precise ordering.

Even NTP cannot guarantee:

Node A: 10:00:00.000000
Node B: 10:00:00.000000
Node C: 10:00:00.000000

at exactly the same instant.

So instead of asking:

“What time did this event happen?”

we can ask:

“What event happened before what other event?”

This leads to logical clocks.


7. Vector Clocks

A vector clock doesn't attempt to tell us the actual physical time.

Instead, it tells us about the ordering of events.

For example:

Event A → Event B → Event C

The important information is the sequence:

A happened before B
B happened before C

rather than:

A happened at 10:01:03
B happened at 10:01:05
C happened at 10:01:08

Why is this useful?

Because for distributed systems, we often don't actually care about the exact time.

We care about:

Which operation happened before another operation?


8. Physical Time vs Logical Time

Physical TimeLogical Time
Uses real clocksUses event relationships
NTP can synchronize clocksVector clocks track ordering
Gives approximate timestampsGives ordering information
Can have clock skewDoesn't depend on synchronized clocks
Useful for Last Write WinsUseful for determining causality/order
Easier to implementMore complex

9. Important Concept — Time vs Ordering

This is the key takeaway from this section.

Physical clocks

Tell us approximately:

WHEN did something happen?

Logical clocks / Vector clocks

Tell us:

WHAT happened before WHAT?

For distributed systems, ordering is often more important than exact time.


10. Trade-off

There is no perfect solution.

NTP

Pros

  • Simple

  • Widely deployed

  • Practical

  • Good enough for many applications

Cons

  • Not perfectly accurate

  • Clock skew remains

  • Cannot guarantee exact simultaneous time

Vector Clocks

Pros

  • Don't depend on synchronized physical clocks

  • Can establish a formally valid ordering

  • Useful for distributed consistency and conflict detection

Cons

  • More complex

  • Additional metadata

  • More application-level complexity


⭐ Interview Takeaways

Remember these points:

1. Why is synchronization difficult?
Because distributed nodes operate concurrently and there is no perfectly shared global clock.

2. Why do we need synchronization?
To determine the ordering of operations, especially when replicated data contains conflicting values.

3. Common solution for physical time?
NTP (Network Time Protocol).

4. Why not GPS everywhere?
It can provide highly accurate time but is impractical and expensive for most distributed systems.

5. What if physical time isn't accurate enough?
Use logical clocks, such as vector clocks.

6. What does a vector clock tell us?
Not the exact time, but the ordering/causal relationship between events.

🧠 One-line memory trick

NTP tells us approximately “WHEN”; Vector Clocks tell us “WHICH CAME BEFORE WHICH.”


-----

Vector Clock:

Absolutely. Vector Clock is much easier if you first understand the problem it solves.

1. The basic problem

Imagine 3 servers:

        Distributed System

   Node A        Node B        Node C
     |              |             |
     |              |             |
   Event          Event         Event

All nodes work independently.

There is no perfectly synchronized clock.

So if:

Node A says: 10:05:01
Node B says: 10:05:00

we cannot always trust the timestamps to determine which event actually happened first.

Instead, we want to know:

Did Event X happen before Event Y?

That's what a vector clock helps us determine.


2. Think of a vector clock as a scoreboard

Suppose we have 3 nodes:

A    B    C

Each node maintains a vector containing a counter for every node.

Initially:

A = [0,0,0]
B = [0,0,0]
C = [0,0,0]

The positions always mean:

       A  B  C
       ↓  ↓  ↓
Vector [0, 0, 0]

So:

  • position 1 → events known from A

  • position 2 → events known from B

  • position 3 → events known from C


3. Node A performs an event

Suppose A performs:

A: Write "Americano"

A increments its own counter:

A = [1,0,0]

Meaning:

A has performed 1 event, and A knows nothing about events from B or C.


4. A sends information to B

Now A sends its data to B.

A = [1,0,0]
       ↓
       B

B receives the message.

B merges the vectors and increments its own counter.

Before:

B = [0,0,0]

After receiving A's information:

B = [1,1,0]

Interpretation:

B knows about 1 event from A and has performed 1 event itself.


5. B performs another event

Suppose B writes:

B: Write "Bread"

B increments its own counter:

B = [1,2,0]

Now B knows:

A → 1 event
B → 2 events
C → 0 events

6. B sends information to C

B sends its vector:

B = [1,2,0]
       ↓
       C

C originally has:

C = [0,0,0]

C receives B's vector and merges:

C = [1,2,0]

Then if C performs an event:

C = [1,2,1]

Now C knows about:

A → 1
B → 2
C → 1

7. The REALLY important part — comparing vectors

This is where vector clocks become powerful.

Suppose we have two events:

Event X → [2,1,0]

Event Y → [2,3,0]

Compare each position:

       A  B  C
X =   [2, 1, 0]
Y =   [2, 3, 0]
       ↑  ↑  ↑

For every position:

X <= Y

and at least one position is strictly smaller.

Therefore:

X happened before Y.

We write:

X → Y

This is called causal ordering.


8. What if vectors are incomparable?

This is the most important distributed-systems concept.

Suppose:

Event X = [2,1,0]

Event Y = [1,0,3]

Compare:

       A  B  C
X =   [2, 1, 0]
Y =   [1, 0, 3]

X is greater than Y for A and B:

2 > 1
1 > 0

But X is less than Y for C:

0 < 3

So neither vector is completely greater than the other.

Therefore:

Neither event happened before the other.

They are concurrent events.

       X
      ↗
     ?
      ↘
       Y

More accurately, they happened independently.


9. Why is this useful for replicated data?

Go back to our original example:

Replica A → Americano
Replica B → Americano
Replica C → Bread

Suppose:

Americano → [2,1,0]
Bread     → [1,0,1]

The vectors are incomparable.

That tells us:

These two writes happened independently/concurrently.

This is very different from simply saying:

"Bread has the bigger timestamp, so Bread wins."

Vector clocks allow the system to detect the conflict instead of incorrectly assuming an ordering.

The application can then decide what to do:

Americano
    +
Bread
    ↓
Conflict resolution

10. Simple real-world analogy

Think of three people maintaining notebooks:

Ramesh    Suresh    Mahesh

Each person records:

"How many actions have I seen from each person?"

Ramesh's notebook:

[Ramesh=3, Suresh=2, Mahesh=1]

This means Ramesh knows:

  • 3 Ramesh events

  • 2 Suresh events

  • 1 Mahesh event

The vector isn't saying:

"It is 10:32 AM."

Instead, it's saying:

"Here is what I know about the history of events."

That's the key idea.


11. Vector Clock Rules

Remember these 3 rules for interviews.

Rule 1 — Local event

When a node performs an event:

increment your own counter

Example:

[1,2,0] → [1,3,0]

for Node B.


Rule 2 — Send message

Attach your vector to the message.

A = [2,1,0]

       message
          ↓

B receives [2,1,0]

Rule 3 — Receive message

Receiver takes the maximum of each position, then increments its own counter.

Example:

B current = [1,3,0]
message    = [2,1,4]

Take maximum:

[2,3,4]

Then B increments its own position:

[2,4,4]

12. The Most Important Comparison Rule

Given:

X = [x1,x2,x3]
Y = [y1,y2,y3]

X happened before Y if:

x1 <= y1
x2 <= y2
x3 <= y3

and at least one is strictly smaller.

Then:

X → Y

Concurrent if:

Some values are greater and some are smaller.

Example:

X = [2,4,1]
Y = [3,2,5]

Because:

2 < 3
4 > 2
1 < 5

Neither dominates the other.

Therefore:

X || Y

They are concurrent.


🧠 One-line memory trick

Vector Clock = "Who knows how many events from whom?"

And remember:

NTP asks: "What time is it?"
Vector Clock asks: "What happened before what?"

That's why vector clocks are useful when exact physical time is unreliable but event ordering/causality matters


------------------

NTP ***

NTP — Class Notes

1. What is NTP?

NTP = Network Time Protocol

NTP is the most widely used mechanism for synchronizing clocks across computers in a distributed system.

The basic problem is:

Every server has its own clock, but we want all servers to have a reasonably consistent idea of the current time.

NTP doesn't provide perfectly identical time. Instead, it tries to get clocks close enough by measuring and compensating for network delay.


2. Why Can't We Simply Ask a Time Server?

Suppose we have a highly accurate clock somewhere on the Internet:

Very Accurate Clock
       |
       ↓
  Time Server
       |
    Internet
       |
       ↓
    Client

The clock itself might be extremely accurate.

But there is a problem:

Network latency

Suppose the client asks:

"What time is it?"

The request takes 40 ms to reach the server.

The response takes 60 ms to come back.

The client receives the answer 100 ms after sending the request.

If the client simply uses the returned timestamp, it could be approximately 60 ms behind the actual time.

So:

Accurate clock + inaccurate network = inaccurate result

NTP solves this by measuring the network delay and compensating for it.


3. NTP Uses Stratum

NTP organizes time servers into layers called strata.

                Stratum 0
       ┌──────────────────────┐
       │ Atomic Clock / GPS   │
       └──────────┬───────────┘
                  ↓
                Stratum 1
          ┌───────────────┐
          │ Time Server   │
          └───────┬───────┘
                  ↓
                Stratum 2
          ┌───────────────┐
          │ Time Server   │
          └───────┬───────┘
                  ↓
                Stratum 3
          ┌───────────────┐
          │ Time Server   │
          └───────┬───────┘
                  ↓
                 ...

Stratum 0

These are the actual highly accurate time sources:

  • Atomic clocks

  • GPS receivers

  • Other precision reference clocks

Technically, Stratum 0 is the reference clock itself, not a normal network server.


4. Stratum 1

A Stratum 1 server is directly connected to a Stratum 0 reference clock.

Atomic Clock
     ↓
Stratum 1 Server

The server can obtain extremely accurate time from the reference clock.

There may still be tiny amounts of error due to:

  • Hardware

  • Device drivers

  • Interrupts

  • I/O

  • Operating-system scheduling

But the error is very small compared with Internet network latency.


5. Stratum 2 and Beyond

A Stratum 2 server synchronizes with a Stratum 1 server:

Stratum 0
   ↓
Stratum 1
   ↓
Stratum 2
   ↓
Stratum 3
   ↓
Stratum 4

And so on.

The further you move away from the reference clock, the more uncertainty can accumulate.

The important practical point from the lecture is:

NTP normally aims for roughly ±10 ms accuracy over ordinary network paths.

NTP supports a maximum stratum depth of 15 for normal synchronization; Stratum 16 represents an unsynchronized/unusable state.


6. Why Do We Need Multiple Strata?

Imagine millions of computers all connecting directly to one Stratum 1 server:

             Stratum 1
                 |
     ┌───────────┼───────────┐
     ↓           ↓           ↓
  Client       Client      Client
     ↓           ↓           ↓
  Client       Client      Client

The server would have to handle enormous traffic.

Instead, we create a hierarchy:

             Stratum 1
            /         \
           ↓           ↓
      Stratum 2    Stratum 2
       /   \        /   \
      ↓     ↓      ↓     ↓
     S3    S3     S3    S3

This creates fan-out and distributes the load.

In practice, many systems use relatively low stratum numbers such as 2, 3, 4, etc.; reaching the maximum depth is uncommon.


7. NTP Protocol Details

Some useful facts:

PropertyNTP
ProtocolUDP
Port123
Timestamp64 bits
Seconds portion32 bits
Fraction portion32 bits

So an NTP timestamp contains:

┌───────────────────────┬───────────────────────┐
│       32 bits         │        32 bits        │
│       Seconds         │   Fractional seconds  │
└───────────────────────┴───────────────────────┘

This gives very high timestamp resolution.

However, the 32-bit seconds field creates a 2036 rollover issue for the traditional NTP era representation.


8. The Four Important Timestamps

This is the most important technical part.

NTP uses four timestamps:

T0 = Client sends request
T1 = Server receives request
T2 = Server sends response
T3 = Client receives response

Think of the communication like this:

             CLIENT                         SERVER

               T0
               |
               | -------- Request -------->
               |                           T1
               |                           |
               |                           |
               |                           T2
               | <-------- Response --------
               |
               T3

Let's understand each one.

T0 — Client transmit time

The client records:

"I am sending the request now."

T1 — Server receive time

The server records:

"I received the request now."

T2 — Server transmit time

The server records:

"I am sending the response now."

T3 — Client receive time

The client records:

"I received the response now."


9. Round-Trip Time

The total time between sending the request and receiving the response is:

T3 − T0

But this includes:

Client → Server network delay
+
Server processing time
+
Server → Client network delay

The server processing time is:

T2 − T1

Therefore, estimated network round-trip delay is:

(T3 − T0) − (T2 − T1)

This is a very important NTP calculation.


10. Clock Offset

NTP also estimates the difference between the client's clock and the server's clock.

The standard offset calculation is:

Offset = [(T1 − T0) + (T2 − T3)] / 2

You don't necessarily need to memorize the derivation immediately.

The intuition is more important:

NTP uses the four timestamps to estimate both network delay and clock difference.

Then the client can adjust its clock.


11. Simple Example

Suppose:

T0 = 10:00:00.000
T1 = 10:00:00.050
T2 = 10:00:00.052
T3 = 10:00:00.102

Step 1 — Total round trip

T3 - T0
= 102 ms

Step 2 — Server processing time

T2 - T1
= 2 ms

Step 3 — Estimated network time

102 ms - 2 ms
= 100 ms

So approximately 100 ms was spent traveling through the network.

Assuming roughly symmetric network delay, NTP can estimate the clock offset from the four timestamps.


12. Why Does NTP Need Repeated Measurements?

One request isn't enough.

Network latency constantly changes:

Request 1 → 80 ms
Request 2 → 120 ms
Request 3 → 95 ms
Request 4 → 200 ms
Request 5 → 90 ms

Therefore NTP continually takes measurements.

It then uses filtering/statistical techniques to determine:

"What is the most reasonable estimate of the current network delay and clock offset?"

This makes NTP adaptive.


13. The Key Idea

The most important thing to understand is:

              Accurate Clock
                    ↓
              Time Server
                    ↓
          Network introduces delay
                    ↓
              NTP measures it
                    ↓
       NTP compensates for delay
                    ↓
        Client gets estimated time

So NTP isn't magically making the network instantaneous.

It is essentially saying:

"I know the answer arrived late. Let me estimate how late it was and compensate for that."


14. NTP vs Vector Clock

This connects directly to your previous class.

NTPVector Clock
Physical timeLogical time
Answers approximately "When?"Answers "What happened before what?"
Synchronizes clocksTracks causal ordering
Uses network time serversUses counters/vectors
Subject to clock/network uncertaintyDoesn't require synchronized clocks
Useful for timestampsUseful for distributed causality/conflicts

🧠 Easy memory trick

NTP = approximate real-world time
Vector Clock = logical ordering of events

And the big distributed-systems lesson is:

There is no perfect "NOW" in a distributed system. NTP gives us a good approximation; vector clocks avoid needing exact physical time when all we really need is event ordering.



VECTOR CLOCKS:

Vector Clocks — Class Notes

1. First: What Is a Vector Clock?

The most important point from the lecture:

A vector clock does NOT tell us the actual time.

Despite the word “clock”, it is not a physical clock.

NTP gives us an approximate idea of when something happened. Vector clocks are used for a different purpose:

To prove the sequence/ordering of operations in a distributed system.

Think:

NTP          → "When did it happen?"
Vector Clock → "Which operation happened before which?"

2. The Problem Vector Clock Solves

Imagine a distributed database containing one value:

Coffee Meeting Day = ?

Several users can modify this value concurrently.

The four actors are:

Alice
Bob
Kathy
Dave

Each actor has:

  1. A unique ID

  2. A local counter

Every time that actor modifies the value, it increments its own counter.

For example:

Alice → A
Bob   → B
Kathy → C
Dave  → D

The important thing is that each actor maintains its own counter locally. It is not a distributed counter.


3. Alice Makes the First Change

Suppose Alice says:

Wednesday

Her first write is:

Wednesday [A1]

The A1 means:

A = Alice
1 = Alice's first modification

So the vector is essentially:

[A:1]

The vector travels along with the value. You cannot just send:

Wednesday

You send:

Wednesday + vector information

This lets the system understand the history of the value.


4. Network Partition Happens

Now imagine the network gets partitioned.

        Network Partition

 Alice ─── Kathy       Bob ─── Dave

Alice and Kathy cannot communicate with Bob and Dave.

This is a very realistic distributed-systems situation.


5. Bob Changes the Value

Bob doesn't agree with Wednesday.

He says:

Tuesday

Bob knows about Alice's previous write:

A1

So Bob creates:

Tuesday [A1 B1]

Meaning:

A1 → Alice's first write
B1 → Bob's first write

Bob's own counter is B1.

Importantly, Bob does not need to maintain Alice's counter himself. Each actor is responsible for its own counter.


6. Dave Agrees With Bob

Dave receives Bob's version:

Tuesday [A1 B1]

Dave says:

Yes, Tuesday.

Dave performs his own write.

So:

Tuesday [A1 B1 D1]

Now the history says:

Alice → Bob → Dave

because each subsequent operation contains the previous operation's vector information.


7. Kathy Doesn't Know About Bob or Dave

Meanwhile, Kathy is still on Alice's side of the partition.

She only knows:

Alice → Wednesday [A1]

But Kathy decides:

Thursday

Her write becomes:

Thursday [A1 C1]

Notice something very important:

Kathy doesn't know about Bob or Dave.

So her vector contains:

A1
C1

but not:

B1
D1


8. Partition Heals — Conflict!

Now Dave receives Kathy's version:

Thursday [A1 C1]

But Dave currently has:

Tuesday [A1 B1 D1]

So we have:

Version 1:
Tuesday  [A1 B1 D1]

Version 2:
Thursday [A1 C1]

Which one is newer?

This is where vector clocks become powerful.


9. How Do We Detect a Conflict?

To determine whether one version is a descendant of another, we need to check whether the vector contains all the information from the earlier version.

Compare:

Tuesday  → [A1 B1 D1]
Thursday → [A1 C1]

Look at Tuesday:

A1
B1
D1

Look at Thursday:

A1
C1

Thursday does not contain:

B1
D1

Therefore:

Thursday cannot be a descendant of Tuesday.

Likewise, Tuesday doesn't contain Kathy's C1.

Therefore:

Neither version is a descendant of the other.

They are concurrent/conflicting versions.


10. This Is the Heart of Vector Clocks

Remember this rule:

If Vector B contains everything represented by Vector A, plus something newer:

A → B

B is a descendant of A.

But if:

A has something B doesn't have
AND
B has something A doesn't have

then:

A || B

They are concurrent.

Example

A = [1,2,0]
B = [1,3,0]

B contains everything from A and has a newer B component.

Therefore:

A → B

But:

A = [1,2,0]
B = [1,0,3]

Neither contains the other's complete history.

Therefore:

A || B

Conflict.


11. What Happens When There Is a Conflict?

This is a very important point from the class.

The database doesn't magically know which business decision is correct.

It tells the application:

"You have two different histories. Resolve the conflict."

In the example:

Tuesday  [A1 B1 D1]
Thursday [A1 C1]

Dave decides:

Thursday

and creates another version:

Thursday [A1 B1 C1 D2]

Dave's counter is now D2 because this is his second write.


12. Why Does the Application Need to Resolve It?

This is one of the biggest disadvantages of vector clocks.

Suppose the value wasn't:

Tuesday / Thursday

but a customer record:

Customer
---------
Name
Phone
Address
Email

You might have:

Version A:
Phone changed

Version B:
Address changed

Instead of throwing one version away, the application might be able to merge:

Phone  ← Version A
Address ← Version B

But the database cannot necessarily know the business semantics.

Therefore:

Conflict resolution is pushed toward the application/client.


13. An Interesting Case: No Conflict

Later, Alice sees two versions:

Tuesday  [A1 B1 D1]
Thursday [A1 B1 C1 D2]

Now look carefully.

The Thursday vector contains the history from Tuesday:

A1
B1
D1

plus:

C1
D2

So Thursday is a descendant of Tuesday.

Therefore the database can automatically determine:

Tuesday
   ↓
Thursday

There is no need to ask the application to resolve a conflict.

The newer history wins because it contains the complete history of the older version.


14. Visualizing the Whole Example

                     Alice
                       |
                Wednesday [A1]
                       |
              ─── Network Partition ───
               /                     \
             Kathy                   Bob
               |                      |
        Thursday [A1 C1]       Tuesday [A1 B1]
                                      |
                                     Dave
                                      |
                            Tuesday [A1 B1 D1]

              Partition heals
                      |
                      ↓

        ┌──────────────────────────────┐
        │                              │
 Tuesday [A1 B1 D1]    Thursday [A1 C1]
        │                              │
        └────── CONFLICT ──────────────┘
                      |
                      ↓
             Application resolves
                      |
                      ↓
             Thursday [A1 B1 C1 D2]

15. Vector Clock vs Last Write Wins

This is the important trade-off discussed in the lecture.

Last Write Wins (LWW)

LWW uses timestamps:

Value A → 10:05:01
Value B → 10:05:03

Winner → B

Simple.

But clock differences can cause the system to get the ordering wrong.

Vector Clock

Vector clocks don't depend on physical timestamps to establish causal ordering.

They can determine:

A happened before B

or:

A and B happened concurrently

So vector clocks cannot get causal sequence wrong, assuming the implementation is correct.


16. But Vector Clocks Have a Cost

The downside is:

Complexity moves into the client/application.

The database can tell you:

CONFLICT!

But your application has to decide:

Which value should win?
OR
Can the two values be merged?

And application-level conflict-resolution code can itself contain bugs.

So:

Vector Clock
     ↓
Correct causal ordering
     ↓
Detect conflicts
     ↓
Application must resolve conflict

17. When Should You Care About Vector Clocks?

The lecture gives a useful practical guideline:

Ask yourself:

"Is time a first-class object in my domain?"

For example, if you're building a system where exact ordering is critical, vector clocks may be valuable.

If users are simply clicking buttons and two operations happen very close together, a tiny timestamp-ordering error may not matter much.

So don't automatically choose vector clocks just because they are theoretically more correct.


⭐ Interview Summary

What is a vector clock?

A mechanism for tracking causal ordering of events in a distributed system, not a mechanism for measuring physical time.

Why do we need it?

Because multiple nodes can modify the same data concurrently and there is no perfectly synchronized global clock.

What does each node maintain?

A local counter identified by that node's unique ID.

What does the vector represent?

The known history/sequence of modifications.

How do we detect a conflict?

If neither vector contains the complete history represented by the other, the versions are concurrent.

Who resolves the conflict?

Usually the application/client, based on business semantics.

Biggest advantage?

Causal sequence cannot be incorrectly determined when the vector-clock implementation is correct.

Biggest disadvantage?

Conflict-resolution complexity is pushed into the application.


🧠 The 3 things to remember

VECTOR CLOCK

1. NOT actual time
        ↓
2. Tracks causality/history
        ↓
3. Detects concurrent conflicts

And the simplest mental model is:

"A vector clock is a distributed history tracker."

It answers:

“What changes does this version know about, and is this version a descendant of another version?” 

Distributed Computations -

 

Distributed Computation — Class Notes

1. Why Distributed Computation?

When data is distributed across many computers/nodes, we often need to perform computation or analysis on that data.

Example:

Node 1 → Data A
Node 2 → Data B
Node 3 → Data C
Node 4 → Data D
        ↓
   Distributed Data
        ↓
   Computation

Instead of moving all the data to one machine, we prefer to move the computation to where the data is located.

Key principle

Move the program to the data, rather than moving huge amounts of data to the program.

This is one of the most important ideas in distributed computation.


2. Scatter → Compute → Gather

A common distributed-computation paradigm is:

             SCATTER
                ↓
       ┌────────┼────────┐
       ↓        ↓        ↓
     Node 1   Node 2   Node 3
       ↓        ↓        ↓
    Compute   Compute   Compute
       ↓        ↓        ↓
       └────────┼────────┘
                ↓
             GATHER
                ↓
           Final Result

Three major steps

1. Scatter

Break the computation into smaller pieces and send them to multiple nodes.

2. Compute

Each node processes the computation, preferably using local data.

3. Gather

Collect the individual results and combine them into the final result.

This is commonly called the Scatter-Gather pattern.


3. Why Should Computation Be Near the Data?

Consider two computers connected through a network.

CPU ↔ Memory ↔ Disk
       |
       |
    Network
       |
       |
CPU ↔ Memory ↔ Disk

Even if the network is extremely fast, communication within a single computer is generally faster than communication across a network.

Why?

Inside a machine we have:

  • High-bandwidth memory buses

  • Very short physical distances

  • Fast CPU ↔ memory communication

  • Fast CPU ↔ local storage communication

  • Common system clock

Network communication introduces additional:

  • Network latency

  • Serialization/deserialization

  • Packet transmission

  • Network congestion

  • Remote data transfer overhead

Therefore:

Moving computation is often cheaper than moving large amounts of data.

This concept is called data locality.


4. Data Locality

Data locality means performing computation as close as possible to the data being processed.

For example:

Bad approach

10 TB Data
   ↓
Network
   ↓
One Computer
   ↓
Process

Moving 10 TB across the network can be expensive.

Better approach

Node 1: Data 2.5 TB → Process locally
Node 2: Data 2.5 TB → Process locally
Node 3: Data 2.5 TB → Process locally
Node 4: Data 2.5 TB → Process locally

                ↓

        Small Results
                ↓
        Central Aggregator

Only the relatively small computation results need to be transferred.


5. MapReduce

One of the most famous implementations of the Scatter-Gather idea is MapReduce.

MapReduce is a computational paradigm/pattern, not merely a single piece of code.

It became particularly well known through Hadoop.

The basic idea is:

Input Data
    ↓
   MAP
    ↓
Intermediate Results
    ↓
  REDUCE
    ↓
Final Result

MAP

Processes individual pieces of data in parallel.

REDUCE

Combines the intermediate results into a final answer.


6. Simple MapReduce Example

Suppose we have:

Node 1 → "Java Java Redis"
Node 2 → "Java Spark"
Node 3 → "Redis Spark Java"

Suppose we want to count each word.

Map phase

Each node processes its local data:

Node 1:
Java  → 1
Java  → 1
Redis → 1

Node 2:
Java  → 1
Spark → 1

Node 3:
Redis → 1
Spark → 1
Java  → 1

Shuffle/Group

Group identical keys:

Java  → [1,1,1,1]
Redis → [1,1]
Spark → [1,1]

Reduce

Add the values:

Java  → 4
Redis → 2
Spark → 2

So:

             MAP
              ↓
       Local computation
              ↓
          SHUFFLE
              ↓
       Group by key
              ↓
           REDUCE
              ↓
        Final result

7. Hadoop

Hadoop is a distributed computing ecosystem that became strongly associated with MapReduce.

Two important ideas in Hadoop are:

HDFS

Hadoop Distributed File System

Provides distributed storage.

Large File
   ↓
Split into blocks
   ↓
Node 1
Node 2
Node 3
Node 4

Data is distributed across multiple machines.

MapReduce

Provides distributed computation over that data.

HDFS
 ↓
Distributed Data
 ↓
MapReduce
 ↓
Distributed Processing
 ↓
Result

So Hadoop combines the concepts of:

Distributed Storage + Distributed Computation


8. Spark

Apache Spark is another distributed-computation technology.

Spark also follows the broad idea of distributing computation across multiple machines, but its programming model and data-processing approach differ significantly from traditional Hadoop MapReduce.

Conceptually:

Distributed Data
       ↓
      Spark
       ↓
Parallel Processing
       ↓
   Final Result

Hadoop MapReduce vs Spark — high level

FeatureHadoop MapReduceSpark
ComputationDistributedDistributed
Main paradigmMap → Shuffle → ReduceTransformations + Actions
Programming modelMore rigidMore flexible
Iterative processingRelatively expensiveGenerally much better
Interactive analyticsLess suitableBetter suited
Machine learningPossibleStrong ecosystem
StreamingSeparate solutions commonly usedStrong streaming support

Important

Don't think:

Hadoop = storage and Spark = computation

The reality is more nuanced.

Hadoop commonly includes HDFS + MapReduce + resource-management components, while Spark is primarily a distributed computation engine and can work with different storage systems.


9. Hadoop vs Spark — How to Think About It

A useful mental model:

                Distributed Computation
                        |
              ┌─────────┴─────────┐
              ↓                   ↓
         Hadoop MapReduce       Spark
              ↓                   ↓
       Map → Shuffle → Reduce   Transformations
                                + Actions

Both distribute computation.

The difference is primarily in their execution model, programming model, performance characteristics, and use cases.


10. Apache Storm

Apache Storm addresses a different type of distributed-computation problem.

Hadoop MapReduce is traditionally associated with batch processing.

Storm is designed around event/stream processing.

Batch processing

Data is already stored:

Huge Data
   ↓
Distributed Storage
   ↓
Batch Processing
   ↓
Result

Example:

Analyze yesterday's 500 GB transaction data.

Event processing

Events continuously arrive:

Event → Event → Event → Event → Event
   ↓       ↓       ↓       ↓
        Storm
          ↓
   Real-time Processing

Example:

Detect suspicious transactions as they happen.


11. Batch vs Real-Time Processing

This is an important interview concept.

Batch ProcessingEvent/Stream Processing
Processes accumulated dataProcesses incoming events
Higher latency acceptableLow latency important
Large datasetsContinuous streams
Periodic computationContinuous computation
Hadoop MapReduce is an exampleStorm is an example

Example

Batch:

Every night calculate total sales for the day.

Real-time:

Immediately detect a suspicious credit-card transaction.


12. Lambda Architecture

Sometimes an application needs both batch processing and real-time processing.

This leads to the idea of Lambda Architecture.

Conceptually:

                    Incoming Data
                         |
              ┌──────────┴──────────┐
              ↓                     ↓
        Batch Layer             Speed Layer
              ↓                     ↓
       Historical Data         Real-time Data
              ↓                     ↓
              └──────────┬──────────┘
                         ↓
                    Serving Layer
                         ↓
                      Result

Batch Layer

Processes large amounts of historical data.

Advantages:

  • Accurate

  • Comprehensive

  • Can recompute historical results

Speed Layer

Processes new events quickly.

Advantages:

  • Low latency

  • Real-time results

  • Immediate updates

Serving Layer

Combines or exposes the results to applications/users.


13. Important Distributed Computation Concepts

1. Data Locality

Keep computation close to the data.

2. Parallelism

Multiple nodes process different portions of the workload simultaneously.

3. Scatter-Gather

Scatter → Process → Gather

4. MapReduce

Map → Shuffle → Reduce

5. Batch Processing

Process accumulated data periodically.

6. Stream/Event Processing

Process events continuously as they arrive.

7. Distributed Storage

Data is distributed across multiple machines so computation can happen close to it.


14. Big Picture

The entire topic can be remembered using this diagram:

              DISTRIBUTED DATA
                     |
                     ↓
          Move computation to data
                     |
                     ↓
             SCATTER-GATHER
                     |
          ┌──────────┼──────────┐
          ↓          ↓          ↓
        Node 1     Node 2     Node 3
          ↓          ↓          ↓
       Compute    Compute    Compute
          └──────────┼──────────┘
                     ↓
                   Gather
                     |
          ┌──────────┼───────────┐
          ↓          ↓           ↓
      MapReduce     Spark       Storm
          ↓          ↓           ↓
        Batch    Distributed   Real-time
                  Compute       Events
          \          |           /
           \         |          /
            └────────┼─────────┘
                     ↓
              Lambda Architecture
             Batch + Real-time

⭐ Interview Takeaways

  1. Why distributed computation?
    To process very large datasets using multiple machines in parallel.

  2. Why move computation to data?
    Network transfer is usually more expensive than local computation.

  3. What is data locality?
    Processing data on or near the node where it is stored.

  4. What is Scatter-Gather?
    Scatter computation → process in parallel → gather results.

  5. What is MapReduce?
    A distributed computational paradigm consisting primarily of Map, Shuffle/Group, and Reduce stages.

  6. What is Hadoop?
    A distributed-data ecosystem historically centered around HDFS and MapReduce.

  7. What is Spark?
    A general-purpose distributed computation engine with a different programming/execution model from classic MapReduce.

  8. What is Storm?
    A distributed stream/event-processing system designed for low-latency processing.

  9. Batch vs real-time?
    Batch processes accumulated data; real-time processing handles events as they arrive.

  10. Lambda Architecture?
    A design combining batch processing and real-time processing to provide both comprehensive and low-latency results.

--------------------------------
Map Reduce - 1

MapReduce — Class Notes

1. What is MapReduce?

MapReduce is primarily a computation pattern, not a programming language, product, or specific open-source project.

It is a mathematical/computational abstraction that helps us divide a large computation into pieces that can be executed across many machines.

Core idea

Break a large computation into smaller parallel computations, process data near where it is stored, then combine the results.

MapReduce became famous through Hadoop, but:

MapReduce ≠ Hadoop

  • MapReduce → computation pattern

  • Hadoop MapReduce → an implementation of that pattern


2. Why MapReduce?

Suppose we have:

100 TB Data
   ↓
Distributed across
100 computers

A traditional program might try to bring the data to one machine:

100 TB
  ↓
Network
  ↓
One Server
  ↓
Process

That is inefficient.

MapReduce instead tries to do:

             100 TB Data
                  ↓
       ┌──────────┼──────────┐
       ↓          ↓          ↓
     Node 1     Node 2     Node 3
       ↓          ↓          ↓
     Map         Map        Map
       ↓          ↓          ↓
       └──────────┼──────────┘
                  ↓
               Shuffle
                  ↓
                Reduce
                  ↓
              Final Result

The important principle is:

Move computation to the data, instead of moving the data to the computation.


3. MapReduce Gives Us Constraints

MapReduce can initially feel very restrictive.

Instead of writing an arbitrary program, we have to express our computation using two major functions:

MAP
 ↓
REDUCE

Why impose these restrictions?

Because those constraints make it much easier for a framework to:

  • Parallelize computation

  • Distribute work across machines

  • Handle huge datasets

  • Recover from failures

  • Execute work close to data

  • Scale from a few machines to hundreds or thousands

Important lesson

The limitation is actually a strength.

MapReduce sacrifices programming flexibility in exchange for massive scalability.


4. The Two Main Functions

MapReduce revolves around two functions:

Map

Input:
Key + Value

Output:
List of Key + Value pairs

Conceptually:

map(key, value)
        ↓
[(key1,value1), (key2,value2), ...]

Reduce

Input:
Key + List of Values

Output:
Key + Result

Conceptually:

reduce(key, [value1,value2,value3,...])
        ↓
(key,result)

5. Key-Value Pair

MapReduce commonly represents data as:

(Key, Value)

Almost anything can be represented this way.

Examples:

(1, "Hello World")
(2, "Java Redis")
(3, "Spark Hadoop")

The value could also represent:

  • Text

  • Image data

  • Sensor data

  • Serialized objects

  • Database records

  • Log entries

The key is important because MapReduce uses the key to determine how data should be grouped during shuffle.


6. Map Function

The mapper receives one key-value pair.

             Mapper
               ↓
(Key, Value)
               ↓
      List of Key-Value pairs

For example:

Input:

(1, "Java Java Redis")

Mapper might produce:

(Java, 1)
(Java, 1)
(Redis, 1)

The mapper doesn't necessarily have to produce many records.

It can produce just one:

Input:
(100, CustomerRecord)

        ↓ Mapper

(CustomerId, CustomerName)

So:

One input key-value pair → zero, one, or many output key-value pairs.


7. Shuffle — The Hidden but Critical Step

The complete pattern is actually:

MAP → SHUFFLE → REDUCE

People normally call it MapReduce, not MapShuffleReduce.

Why?

Because Shuffle is normally handled automatically by the framework.

The developer generally writes:

Mapper
Reducer

while the framework handles the shuffle.


8. What Does Shuffle Do?

This is one of the most important concepts in MapReduce.

Suppose different nodes produce:

Node 1:
(Java, 1)
(Redis, 1)

Node 2:
(Java, 1)
(Spark, 1)

Node 3:
(Redis, 1)
(Java, 1)

The framework needs to bring all identical keys together.

So shuffle produces:

Java  → [1, 1, 1]
Redis → [1, 1]
Spark → [1]

Now all values belonging to the same key are together.


9. Why Shuffle Can Be Expensive

Suppose:

Node 1 → (Java,1)
Node 2 → (Java,1)
Node 3 → (Java,1)
Node 4 → (Java,1)

These records may initially exist on different machines.

To reduce them together, the framework may need to transfer data across the network.

Node 1 ─────┐
Node 2 ─────┤
Node 3 ─────┼──→ Network → Reducer
Node 4 ─────┘

Therefore:

Shuffle can become a major network and performance bottleneck.

This is one of the most important MapReduce optimization areas.


10. MapReduce Complete Flow

Remember this:

                 INPUT
                   ↓
            Key-Value Pairs
                   ↓
              ┌────────┐
              │   MAP  │
              └────────┘
                   ↓
       List of Key-Value Pairs
                   ↓
              ┌─────────┐
              │ SHUFFLE │
              └─────────┘
                   ↓
       Group by Common Key
                   ↓
          Key + List of Values
                   ↓
              ┌────────┐
              │ REDUCE │
              └────────┘
                   ↓
             Final Results

11. What Exactly Happens During Shuffle?

Suppose mapper outputs:

(A, 10)
(B, 20)
(A, 30)
(C, 40)
(B, 50)

Shuffle groups by key:

A → [10, 30]
B → [20, 50]
C → [40]

Then reducers receive:

Reducer(A, [10,30])
Reducer(B, [20,50])
Reducer(C, [40])

This grouping is the heart of the MapReduce model.


12. Reduce Function

The reducer receives:

Key + List of Values

Example:

(A, [10,30])

The reducer can aggregate:

10 + 30 = 40

Output:

(A, 40)

Similarly:

(B, [20,50])
       ↓
      70

(C, [40])
       ↓
      40

Final:

(A,40)
(B,70)
(C,40)

13. Canonical Example — Word Count

Word Count is the classic MapReduce example.

Input:

Java Java Redis
Java Spark
Redis Spark Java

Step 1 — Input

Imagine the data is distributed:

Node 1:
Java Java Redis

Node 2:
Java Spark

Node 3:
Redis Spark Java

Step 2 — Map

Each mapper processes its local data.

Node 1

(Java,1)
(Java,1)
(Redis,1)

Node 2

(Java,1)
(Spark,1)

Node 3

(Redis,1)
(Spark,1)
(Java,1)

14. Step 3 — Shuffle

The framework groups identical keys:

Java  → [1,1,1,1]
Redis → [1,1]
Spark → [1,1]

Notice something important:

The Java values could have originated from different machines.

Shuffle brings them together logically for reduction.


15. Step 4 — Reduce

Reducer receives:

Java → [1,1,1,1]

and calculates:

1 + 1 + 1 + 1 = 4

Similarly:

Redis → [1,1] → 2
Spark → [1,1] → 2

Final result:

Java  → 4
Redis → 2
Spark → 2

16. Word Count in One Diagram

             INPUT
               ↓
     "Java Java Redis"
     "Java Spark"
     "Redis Spark Java"
               ↓
             MAP
               ↓
     ┌─────────────────────┐
     │ (Java,1)             │
     │ (Java,1)             │
     │ (Redis,1)            │
     │ (Java,1)             │
     │ (Spark,1)            │
     │ (Redis,1)            │
     │ (Spark,1)            │
     │ (Java,1)             │
     └─────────────────────┘
               ↓
            SHUFFLE
               ↓
     ┌─────────────────────┐
     │ Java  → [1,1,1,1]   │
     │ Redis → [1,1]       │
     │ Spark → [1,1]       │
     └─────────────────────┘
               ↓
             REDUCE
               ↓
     ┌─────────────────────┐
     │ Java  → 4           │
     │ Redis → 2           │
     │ Spark → 2           │
     └─────────────────────┘

17. Why Reduce Usually Produces Less Data

Imagine:

Input:
1 TB

Map might produce:

Several TB of intermediate key-value pairs

After grouping and aggregation:

Reduce output:
Few GB

or potentially much less.

Conceptually:

Huge Input
    ↓
   MAP
    ↓
Huge Intermediate Data
    ↓
 SHUFFLE
    ↓
Grouped Data
    ↓
  REDUCE
    ↓
Smaller Aggregate Result

The goal is to turn a massive collection of raw records into useful aggregate information.


18. Map vs Shuffle vs Reduce

StageResponsibility
MapProcess individual input records
ShuffleGroup records by key
ReduceAggregate/process values belonging to each key

Easy memory trick

MAP = Create

Mapper creates intermediate key-value pairs.

SHUFFLE = Group

Framework groups values having the same key.

REDUCE = Combine

Reducer combines those values into a result.


19. Most Important Interview Concept — Shuffle

If you're preparing for distributed-system interviews, pay special attention to Shuffle.

Why?

Because Shuffle can involve:

Disk I/O
+
Network I/O
+
Serialization
+
Deserialization
+
Sorting
+
Data partitioning

Therefore:

MapReduce performance is often heavily influenced by how much data is generated and transferred during shuffle.

This is why MapReduce programming often feels restrictive: the constraints help the framework reason about how to distribute and execute the computation.


20. MapReduce Mental Model

Think of MapReduce as a data transformation pipeline:

                 LARGE DATA
                     ↓
                  MAP
             "Create key/value"
                     ↓
              INTERMEDIATE
                  DATA
                     ↓
                SHUFFLE
             "Group by key"
                     ↓
              GROUPED DATA
                     ↓
                 REDUCE
             "Aggregate"
                     ↓
                RESULT

One-line definition

MapReduce is a distributed computation pattern where Map transforms input records into key-value pairs, Shuffle groups values by key, and Reduce aggregates those grouped values into final results.

⭐ Remember these 6 points

  1. MapReduce is a computation pattern.

  2. Map takes one key-value pair and produces zero/many key-value pairs.

  3. Shuffle groups values having the same key.

  4. Shuffle is generally handled by the framework.

  5. Reduce receives a key and its list of values and produces a result.

  6. The biggest hidden cost can be Shuffle because it may require substantial network data movement.


--------------------------
MapReduce - 2

MapReduce — Class Notes: Word Count Example

This lecture explains the canonical MapReduce Word Count example using Edgar Allan Poe's The Raven. The important goal is not the poem itself, but understanding exactly what happens in Map → Shuffle → Reduce.


1. Input to the Mapper

MapReduce commonly works with key-value pairs.

In this example:

Key   = File name
Value = Contents of the file

For example:

("The_Raven.txt", "Once upon a midnight dreary ...")

The entire text of The Raven is the value.

Important

The input doesn't have to be a poem.

The value could be:

  • Text file

  • Log file

  • Sensor data

  • JSON

  • Database record

  • Image metadata

  • Any serialized data


2. Mapper Tokenizes the Input

The mapper takes the value and tokenizes it.

Suppose the input contains:

"Once upon a midnight dreary"

The mapper breaks it into words:

Once
upon
a
midnight
dreary

But MapReduce requires the mapper to output key-value pairs, not just words.

So we need to decide:

What should the key and value represent?

Since our objective is word counting, the obvious choice is:

Key   = Word
Value = 1

Therefore:

Once     → 1
upon     → 1
a        → 1
midnight → 1
dreary   → 1

Or as MapReduce key-value pairs:

(Once, 1)
(upon, 1)
(a, 1)
(midnight, 1)
(dreary, 1)

3. Why Does Mapper Output 1?

This is an important idea.

The mapper doesn't try to calculate the final word count.

It simply says:

"I found this word once."

For example:

(chamber, 1)
(pondered, 1)
(a, 1)
(a, 1)
(a, 1)

Each mapper has a very simple responsibility:

Input word
    ↓
"I saw this word"
    ↓
(word, 1)

This makes the computation highly parallelizable.


4. Why Is This Design Powerful?

Imagine we have 1 PB of text.

We don't want one machine to process everything.

Instead:

                 1 PB Data
                     ↓
        ┌────────────┼────────────┐
        ↓            ↓            ↓
      Node 1       Node 2       Node 3
        ↓            ↓            ↓
      Mapper       Mapper       Mapper
        ↓            ↓            ↓
     (word,1)     (word,1)     (word,1)

We can split the data into many chunks and have many mappers work simultaneously.

Each mapper only needs to understand its local piece of data.


5. Mapper Doesn't Need Global Knowledge

This is one of the most important MapReduce principles.

Suppose three different machines see the word raven.

Node 1 → (raven, 1)
Node 2 → (raven, 1)
Node 3 → (raven, 1)

None of them needs to know what the other machines are doing.

Each mapper simply says:

"I saw raven once."

This makes the mapper:

  • Simple

  • Stateless in the conceptual model

  • Easy to parallelize

  • Easy to distribute


6. Map Phase

Suppose our input is:

"raven raven tapping"

The mapper produces:

(raven, 1)
(raven, 1)
(tapping, 1)

For a larger file:

                  FILE
                   ↓
                TOKENIZE
                   ↓
        ┌──────────┼──────────┐
        ↓          ↓          ↓
      word       word       word
        ↓          ↓          ↓
     (word,1)   (word,1)   (word,1)

At the end of Map:

We have a large collection of (word, 1) pairs.


7. Shuffle Phase

Now comes one of the most important parts:

Shuffle groups identical keys.

Suppose mappers produce:

(raven, 1)
(a, 1)
(tapping, 1)
(raven, 1)
(a, 1)
(raven, 1)

Shuffle rearranges them:

raven   → [1, 1, 1]
a       → [1, 1]
tapping → [1]

The key is now:

word

and the values are:

list of counts

8. Shuffle May Move Data Across the Network

This is where data locality becomes important.

Suppose:

Node 1:
(raven,1)

Node 2:
(raven,1)

Node 3:
(raven,1)

All raven values need to reach the same reducer/group.

Therefore:

Node 1 ─────┐
            │
Node 2 ─────┼──→ Network ──→ Reducer
            │
Node 3 ─────┘

So when the lecture says the data may "move around", it can literally mean:

Data is transferred between machines over the network.


9. Why Take the Network Hit?

At first this seems contradictory.

We said:

Move computation to the data.

But Shuffle may move data across the network.

Why?

Because after moving the data, we get data locality for the next computation.

For example:

Before Shuffle:

Node 1 → raven = 1
Node 2 → raven = 1
Node 3 → raven = 1

After Shuffle:

Reducer Node:

raven → [1,1,1]

Now the reducer can efficiently process all raven values together.

Key principle

Sometimes we accept network cost during Shuffle to create locality for the Reduce computation.


10. Shuffle Output

The mapper produced:

(word, 1)

But the reducer doesn't receive individual pairs.

Instead, Shuffle converts them into:

(word, [values])

Example:

(raven, [1,1,1])
(a, [1,1])
(tapping, [1])

This is the input format expected by the reducer.


11. Why Are Some Lists Larger?

Suppose the word raven appears 100 times.

Shuffle could produce:

raven → [1,1,1,1,1,1,...]

with 100 values.

If a word appears only once:

dreary → [1]

So:

Word frequency       Shuffle result

1 occurrence         [1]

2 occurrences        [1,1]

5 occurrences        [1,1,1,1,1]

100 occurrences      [1,1,1,.....100 times]

12. Reducer

Now the reducer receives:

Key + List of Values

For example:

raven → [1,1,1]

The reducer simply adds them:

1 + 1 + 1 = 3

Final output:

(raven, 3)

Similarly:

a       → [1,1] → 2
tapping → [1]   → 1

13. Complete Example

Let's put everything together.

Input

"The raven is raven"

Map

(the, 1)
(raven, 1)
(is, 1)
(raven, 1)

Shuffle

the   → [1]
raven → [1,1]
is    → [1]

Reduce

the   → 1
raven → 2
is    → 1

Final output

(the, 1)
(raven, 2)
(is, 1)

14. Multiple Reducers

A very important point from the lecture is that we don't necessarily need one reducer.

Suppose there are millions of words.

We could have:

                 SHUFFLE
                    ↓
          ┌─────────┼─────────┐
          ↓         ↓         ↓
      Reducer 1  Reducer 2  Reducer 3
          ↓         ↓         ↓
        Results   Results   Results

For example:

Reducer 1:
a
b
c
d

Reducer 2:
e
f
g
h

Reducer 3:
i
j
k
l

The framework can partition the keys among reducers.


15. Reduce Can Also Be Performed in Stages

The lecture makes an interesting observation.

If there is too much data to process in one place, we can have multiple reduction stages.

Conceptually:

                    Shuffle
                       ↓
             ┌─────────┼─────────┐
             ↓         ↓         ↓
           Reduce    Reduce    Reduce
             ↓         ↓         ↓
             └─────────┼─────────┘
                       ↓
                 Further Reduce
                       ↓
                  Final Result

This is another example of the functional and composable nature of MapReduce.


16. Why "Dumb" Functions Are Powerful

The lecture repeatedly describes the mapper/reducer as almost "dumb".

That is intentional.

Mapper:

"I saw this word once."

Reducer:

"Give me all values for this word; I'll add them."

Neither needs to understand the entire dataset.

Mapper
  ↓
Local view

Reducer
  ↓
Grouped view

This limited view allows the framework to distribute the work.

This is the big idea:

Simple functions + strict data flow = massive parallelism.


17. MapReduce Architecture — Mental Model

                  DISTRIBUTED FILES
                         ↓
              ┌────────────────────┐
              │      MAP PHASE     │
              └────────────────────┘
                         ↓
                 (word, 1)
                 (word, 1)
                 (word, 1)
                         ↓
              ┌────────────────────┐
              │   SHUFFLE PHASE   │
              │    Group by key   │
              └────────────────────┘
                         ↓
              (word, [1,1,1,...])
                         ↓
              ┌────────────────────┐
              │    REDUCE PHASE   │
              │     Aggregate     │
              └────────────────────┘
                         ↓
                  (word, count)

18. The Most Important Data Transformations

Memorize these three transformations:

Map

(K, V)
  ↓
[(K1,V1), (K2,V2), ...]

Shuffle

[(K,V), (K,V), (K,V)]
          ↓
(K, [V,V,V])

Reduce

(K, [V,V,V])
       ↓
(K, Result)

For Word Count:

Input:
File → Text

       ↓ MAP

(word, 1)

       ↓ SHUFFLE

(word, [1,1,1,...])

       ↓ REDUCE

(word, count)

19. Key Distributed-System Lessons

1. Parallelism

Large data can be divided among many machines.

2. Data locality

Try to process data near where it is stored.

3. Network cost

Shuffle can cause significant network traffic.

4. Simple computation

Map and Reduce functions are intentionally constrained.

5. Scalability

Because computation is split into independent pieces, the system can scale horizontally.

6. Fault tolerance

A distributed framework can detect failed work and execute it again on another node. This is one of the major benefits of having a framework manage the execution rather than manually coordinating machines.


20. Interview-Friendly Summary

StageInputOperationOutput
Map(K,V)Transform/tokenize(K,V) pairs
ShuffleMany (K,V) pairsGroup by key(K,[V])
Reduce(K,[V])Aggregate(K,Result)

Word Count

"The raven raven"
       ↓
     MAP
       ↓
(raven,1)
(raven,1)
       ↓
   SHUFFLE
       ↓
raven → [1,1]
       ↓
    REDUCE
       ↓
raven → 2

⭐ One-line exam answer

MapReduce is a distributed computation pattern in which the Map function converts input records into intermediate key-value pairs, Shuffle groups values having the same key—potentially moving them across the network—and Reduce aggregates each key's values to produce the final result.

⭐ The key insight from this lecture

Map is deliberately simple → Shuffle creates grouping/data locality → Reduce performs aggregation → the framework can execute all of this in parallel across many machines.

-------------------


Hadoop Architecture - Distributed Computation + Distributed Storage

Hadoop — Class Notes

1. What is Hadoop?

Hadoop is a distributed computing ecosystem/framework designed to process very large datasets across many machines.

It became one of the best-known open-source technologies for distributed computation and big-data processing.

A good mental model is:

                    HADOOP
                       |
        ┌──────────────┴──────────────┐
        ↓                             ↓
 Distributed Computation       Distributed Storage
        ↓                             ↓
   MapReduce                       HDFS

So Hadoop is not just MapReduce.

Hadoop broadly provides:

  1. MapReduce API

  2. Job/workload management

  3. HDFS — Hadoop Distributed File System

  4. A large ecosystem of tools built around it


2. Hadoop vs MapReduce

This distinction is extremely important.

MapReduce

MapReduce is a computation pattern:

Map → Shuffle → Reduce

Hadoop

Hadoop provides an implementation/framework that allows distributed MapReduce jobs to actually run across a cluster.

MapReduce
   ↓
Hadoop MapReduce
   ↓
Cluster
   ↓
Multiple machines

Interview answer

MapReduce is a distributed computation model, whereas Hadoop is an ecosystem/framework that provides MapReduce execution, distributed storage through HDFS, and cluster/job management.


3. Hadoop MapReduce API

Hadoop provides APIs/interfaces through which developers can define:

Mapper
Reducer

Conceptually:

Input
  ↓
Mapper
  ↓
Shuffle
  ↓
Reducer
  ↓
Output

The developer writes the computation logic, while Hadoop takes care of much of the distributed execution.


4. Hadoop Job Management

One of Hadoop's major advantages is that you don't manually manage every machine.

Suppose we have:

              Hadoop Cluster
                    |
       ┌────────────┼────────────┐
       ↓            ↓            ↓
     Node 1       Node 2       Node 3

Hadoop can:

  • Distribute computation

  • Schedule tasks

  • Monitor tasks

  • Detect failures

  • Retry failed tasks

  • Run work on nodes containing the required data

  • Manage execution across the cluster


5. Failure Handling

Distributed systems assume that machines can fail.

Suppose:

Mapper Task
     ↓
   Node 2
     ↓
   FAILURE

Hadoop can detect the failure and arrange for the work to be executed again, potentially using another copy of the data.

Conceptually:

Node 1 → Task A ✓
Node 2 → Task B ✗
Node 3 → Retry Task B ✓

This is a major advantage of using a distributed framework rather than manually writing scripts for hundreds of machines.


6. HDFS

Hadoop also includes a distributed storage system:

HDFS = Hadoop Distributed File System

HDFS is designed to store very large files across many machines.

From a user's perspective, HDFS looks somewhat like a normal filesystem.

You can have:

/
├── data/
│   ├── sales.txt
│   ├── customers.txt
│   └── transactions.txt
└── logs/
    ├── app1.log
    └── app2.log

You work with:

  • Files

  • Directories

  • Paths

But underneath, the files are distributed across many machines.


7. HDFS Architecture — Basic Idea

A simplified model:

                    HDFS
                     |
          ┌──────────┴──────────┐
          ↓                     ↓
      NameNode              DataNodes
      Metadata               Actual Data
          |                     |
          |              ┌──────┼──────┐
          |              ↓      ↓      ↓
          |            Node1  Node2  Node3
          |
     File metadata

The important distinction:

NameNode

Manages metadata.

DataNodes

Store the actual data blocks.


8. NameNode

The NameNode is the central metadata manager of HDFS.

It keeps information such as:

  • File names

  • Directory structure

  • File paths

  • Which blocks belong to which files

  • Where those blocks are located

  • Other filesystem metadata

For example:

File:
customer-data.csv

Blocks:
B1
B2
B3
B4

NameNode knows:

customer-data.csv
        |
   ┌────┼────┬────┐
   ↓    ↓    ↓    ↓
  B1   B2   B3   B4
   |    |    |    |
 Node1 Node3 Node2 Node4

It does not primarily store the actual file contents.


9. DataNodes

The actual blocks are stored on DataNodes.

Example:

DataNode 1:
  Block A
  Block C

DataNode 2:
  Block B
  Block D

DataNode 3:
  Block A
  Block B

The blocks are replicated for reliability.


10. Why Replication?

Suppose:

Block A
   ↓
Only Node 1

If Node 1 dies:

Node 1 💥
   ↓
Block A LOST

That's unacceptable.

So HDFS stores multiple copies:

             Block A
            /   |   \
           ↓    ↓    ↓
        Node 1 Node 2 Node 3

If Node 1 fails:

Node 1 💥

Block A still exists:
Node 2 ✓
Node 3 ✓

Therefore:

Replication provides fault tolerance.


11. HDFS Blocks

HDFS doesn't normally store a huge file as one giant object.

It divides it into large blocks.

For example:

1 GB file

        ↓

Block 1
Block 2
Block 3
Block 4
...

The lecture mentions a typical HDFS block size around 128 MB for the version being discussed.

So conceptually:

512 MB File
     ↓
┌─────────┐
│ 128 MB  │ Block 1
├─────────┤
│ 128 MB  │ Block 2
├─────────┤
│ 128 MB  │ Block 3
├─────────┤
│ 128 MB  │ Block 4
└─────────┘

Each block can be stored on a different machine.


12. Why Use Large Blocks?

Traditional operating systems may use relatively small blocks.

HDFS uses much larger blocks because it is designed for large-data workloads.

Imagine a 1 TB dataset.

Using tiny blocks would create an enormous number of blocks and therefore enormous metadata overhead.

Large blocks mean:

Huge File
   ↓
Fewer large blocks
   ↓
Less metadata
   ↓
Efficient distributed storage

This is one reason HDFS is designed for large files and large-scale data processing.


13. HDFS Is Designed for Large Files

HDFS is particularly suited for:

Large files
Large datasets
Sequential access
Batch processing
Distributed computation

It is not intended to behave like a traditional low-latency transactional database.

Think:

HDFS
 ↓
Big Data
 ↓
Large files
 ↓
Batch analytics

rather than:

HDFS
 ↓
Tiny records
 ↓
Millions of random updates
 ↓
OLTP

14. Immutable Blocks

One of the most important concepts in the lecture is:

HDFS blocks are immutable.

Once data is written, you generally don't modify the existing block in place.

Conceptually:

Write:
File A
  ↓
Blocks created
  ↓
Immutable

If you need changed content, you create new data rather than modifying the existing block in place.


15. Why Is Immutability Useful?

At first, immutability looks like a limitation.

Actually, it greatly simplifies distributed storage.

Imagine a replicated block:

             Block A
          /     |     \
         ↓      ↓      ↓
      Node 1  Node 2  Node 3

If you modify Block A in place, the system has to carefully coordinate:

Update Node 1
Update Node 2
Update Node 3

What happens if:

Node 1 updated ✓
Node 2 updated ✓
Node 3 fails ✗

Now replicas may temporarily contain different versions.

With immutable blocks:

Once created, the block doesn't change.

This makes replication and consistency much easier to manage.


16. Immutability = Simplification

A powerful distributed-systems lesson:

Whenever you can make data immutable, many distributed-system problems become easier.

With immutable data:

  • Replication is easier

  • Caching is safer

  • Concurrent reads are easier

  • Coordination is reduced

  • Version management becomes simpler

  • Failure recovery becomes easier

This idea appears in many modern distributed systems as well.


17. Hadoop Ecosystem

Because Hadoop became widely used, a large ecosystem developed around it.

The basic idea:

                    Hadoop
                       |
       ┌───────────────┼────────────────┐
       ↓               ↓                ↓
    HDFS            MapReduce       Ecosystem
                                         |
             ┌──────────┬──────────┬─────┴─────┐
             ↓          ↓          ↓           ↓
            Hive       Pig      HBase       Sqoop

The ecosystem exists partly because writing raw MapReduce jobs can be cumbersome.


18. Why Did the Hadoop Ecosystem Grow?

MapReduce is powerful but restrictive.

For simple Word Count:

Map → Shuffle → Reduce

is easy.

But imagine implementing:

  • Business analytics

  • SQL queries

  • Machine learning

  • Workflow management

  • Data ingestion

  • Logging

  • Database integration

using raw MapReduce.

It becomes painful.

Therefore, higher-level tools appeared.

High-Level Tool
      ↓
   Abstracts
      ↓
   MapReduce
      ↓
    Hadoop

19. Important Hadoop Ecosystem Technologies

Hive

Provides a SQL-like query language for analyzing data stored in Hadoop.

Instead of writing complicated MapReduce code, users can express queries in a SQL-like manner.

SQL-like Query
      ↓
     Hive
      ↓
Distributed Execution

Pig

Pig provides a higher-level data-analysis language.

It is useful for expressing data transformations without manually writing all the MapReduce logic.


HBase

HBase is a column-family NoSQL database designed to run on top of Hadoop/HDFS.

Conceptually:

HBase
  ↓
HDFS
  ↓
Distributed Storage

It provides database-like access patterns that are different from traditional relational databases.


Oozie

Oozie is associated with workflow/job management.

Instead of managing one MapReduce job, you may have:

Job A
  ↓
Job B
  ↓
Job C
  ↓
Job D

Workflow tools help coordinate these jobs.


ZooKeeper

ZooKeeper started as part of the broader Hadoop ecosystem but became useful as a general distributed coordination service.

It can help with things such as:

  • Coordination

  • Configuration

  • Leader election

  • Distributed synchronization

Important:

ZooKeeper is not simply "a Hadoop database"; it is a distributed coordination system used by many distributed applications.


Mahout

Apache Mahout was developed as a machine-learning project associated with the Hadoop ecosystem.

The important historical idea is:

Hadoop
  ↓
Distributed computation
  ↓
Machine Learning
  ↓
Mahout

Cascading

Provides a higher-level API for building data-processing workflows and makes writing MapReduce-style applications easier.


Sqoop

Used historically for moving data between:

Relational Database
        ↕
      Hadoop

For example:

MySQL
  ↓
Sqoop
  ↓
HDFS

Flume / Scribe

These tools were associated with collecting and transporting log/event data into large-scale data systems.

Conceptually:

Application Logs
      ↓
Flume/Scribe
      ↓
Hadoop
      ↓
Analytics

20. Hadoop Ecosystem — Easy Memory Map

                         HADOOP
                            |
             ┌──────────────┴──────────────┐
             ↓                             ↓
            HDFS                       MapReduce
       Distributed Storage          Distributed Compute
             |
             |
     ┌───────┼──────────────────────────────┐
     ↓       ↓       ↓       ↓       ↓      ↓
   HBase    Hive     Pig    Sqoop   Flume  Oozie
     ↓       ↓       ↓       ↓       ↓      ↓
   NoSQL    SQL    Analysis  DB     Logs   Workflow

21. Hadoop Architecture — Big Picture

The lecture is essentially introducing this architecture:

                    HADOOP CLUSTER
                         |
          ┌──────────────┴──────────────┐
          ↓                             ↓
        HDFS                        MapReduce
          |                             |
    ┌─────┴─────┐                 ┌────┴────┐
    ↓           ↓                 ↓         ↓
NameNode    DataNodes           Mapper    Reducer
    |           |                 |         |
 Metadata    Data Blocks       Compute   Aggregate
                |
          Replicated Blocks

The important relationship is:

HDFS stores the data; MapReduce processes the data.

And Hadoop's job-management mechanisms coordinate that processing.


22. How MapReduce Uses HDFS

This connects the previous class to this one.

Suppose HDFS contains:

File
 ↓
Block 1 → Node 1
Block 2 → Node 2
Block 3 → Node 3

MapReduce tries to execute:

Block 1 → Mapper on/near Node 1
Block 2 → Mapper on/near Node 2
Block 3 → Mapper on/near Node 3

This is data locality.

Instead of:

Node 1 data
   ↓
Network
   ↓
Central machine
   ↓
Compute

we prefer:

Node 1 → Local Mapper
Node 2 → Local Mapper
Node 3 → Local Mapper

That is a fundamental Hadoop design principle.


23. Critical Hadoop Concepts for Interviews

Q1. What is Hadoop?

Hadoop is a distributed computing ecosystem/framework for storing and processing very large datasets across clusters of commodity machines.

Q2. Is Hadoop the same as MapReduce?

No.

MapReduce = Computation model
Hadoop = Ecosystem/framework implementing distributed storage and computation

Q3. What is HDFS?

HDFS is Hadoop's distributed filesystem designed for storing very large files across multiple machines using large, replicated blocks.

Q4. What is a NameNode?

The NameNode manages HDFS filesystem metadata such as filenames, directories, file-to-block mappings, and block locations.

Q5. What is a DataNode?

A DataNode stores the actual HDFS data blocks.

Q6. Why are HDFS blocks replicated?

To provide fault tolerance when machines or disks fail.

Q7. Why are HDFS blocks large?

Large blocks reduce metadata overhead and are appropriate for large sequential data-processing workloads.

Q8. Why is immutability useful?

Immutable blocks reduce coordination and consistency complexity during replication and distributed processing.


24. The Most Important Mental Model

Keep these four concepts connected:

              HADOOP
                |
       ┌────────┴────────┐
       ↓                 ↓
      HDFS           MapReduce
       ↓                 ↓
    Storage          Computation
       ↓                 ↓
 Large Blocks      Map → Shuffle → Reduce
       ↓                 ↓
   Replication       Parallelism
       └────────┬────────┘
                ↓
        Distributed Processing

⭐ One-line summary

Hadoop combines distributed storage (HDFS), distributed computation (historically MapReduce), and cluster/job management, with a large ecosystem of higher-level tools that make large-scale data processing easier.

⭐ The 5 concepts to remember

HDFS → NameNode → DataNode → Blocks → Replication

And connect them with:

MapReduce → Data Locality → Map → Shuffle → Reduce

That gives you the foundation needed to understand the Hadoop architecture in the next class.


----------------------------

Hadoop Architecture — Class Notes

This class connects the two major sides of Hadoop:

HADOOP
  ├── HDFS       → Distributed Storage
  └── MapReduce  → Distributed Computation

The most important thing to understand is how NameNode, DataNode, JobTracker, TaskTracker, Map, Shuffle and Reduce work together.


1. HDFS Architecture

The basic HDFS architecture has:

  • NameNode

  • DataNodes

  • Clients

                    HDFS
                     |
                 NameNode
              (File Metadata)
                     |
          ┌──────────┼──────────┐
          ↓          ↓          ↓
       DataNode 1 DataNode 2 DataNode 3
          ↓          ↓          ↓
        Blocks     Blocks     Blocks

2. NameNode

The NameNode is the master of HDFS metadata.

It maintains information about:

  • File names

  • Directory paths

  • File-to-block mapping

  • Locations of blocks

  • Filesystem metadata

For example:

/customer/data.txt

     ↓

Block A
Block B
Block C

The NameNode knows:

Block A → DataNode 1
Block B → DataNode 2
Block C → DataNode 3

Important

The NameNode does not normally contain the actual file data.

It contains the metadata describing where the data lives.


3. DataNodes

DataNodes store the actual HDFS blocks.

Example:

DataNode 1
 ├── Block A
 ├── Block D
 └── Block F

DataNode 2
 ├── Block B
 ├── Block A
 └── Block E

DataNode 3
 ├── Block C
 ├── Block B
 └── Block F

The blocks are replicated across DataNodes.


4. Client → NameNode → DataNode

One of the most important architectural ideas is that the client does not send all file data through the NameNode.

Suppose the client wants to create a file.

Step 1 — Client contacts NameNode

Client
   |
   | "I want to create a file"
   ↓
NameNode

The NameNode determines where the blocks should be stored.

For example:

NameNode
   ↓
"Use DataNode 3"

Step 2 — Client sends actual data directly

Client
   |
   | Actual file data
   ↓
DataNode 3

This is important for scalability.


5. Why Doesn't Data Flow Through the NameNode?

Imagine 1,000 clients writing huge files.

If all data had to go through the NameNode:

Client 1 ─┐
Client 2 ─┤
Client 3 ─┤
Client 4 ─┼──→ NameNode ──→ DataNodes
   ...    │
Client N ─┘

The NameNode would become a massive I/O bottleneck.

Instead:

             NameNode
           Metadata only
                |
     ┌──────────┼──────────┐
     ↓          ↓          ↓
  DataNode   DataNode   DataNode
     ↑          ↑          ↑
     |          |          |
   Client     Client     Client

The NameNode handles relatively small amounts of metadata traffic, while DataNodes handle the heavy data traffic.


6. Scalability Through DataNodes

This gives Hadoop substantial aggregate I/O capacity.

Suppose:

DataNode 1 → 1 GB/s
DataNode 2 → 1 GB/s
DataNode 3 → 1 GB/s
DataNode 4 → 1 GB/s

The cluster can potentially provide substantial aggregate throughput.

So HDFS scalability depends heavily on:

  • Network architecture

  • Number of DataNodes

  • Disk performance

  • Network interfaces

  • Cluster architecture


7. HDFS Replication

Suppose we have:

Block A

HDFS replicates it:

             Block A
            /   |   \
           ↓    ↓    ↓
        Node 1 Node 2 Node 3

The lecture mentions a typical replication factor of 3.

That means:

1 logical block
      ↓
3 physical copies

This protects against machine/disk failures.


8. NameNode Coordinates Replication

The NameNode keeps track of block replicas.

Conceptually:

NameNode
   |
   | "Block A needs replicas"
   |
   ├──→ DataNode 1
   ├──→ DataNode 2
   └──→ DataNode 3

The NameNode therefore maintains the metadata necessary to understand the state of the distributed filesystem.


9. What Happens When a DataNode Fails?

Suppose:

Block A
 ├── Node 1 ✓
 ├── Node 2 ✓
 └── Node 3 ✗

Now the cluster has lost one replica.

HDFS can detect that the replication level has fallen below the desired level and arrange for another copy to be created.

Conceptually:

Block A
 ├── Node 1 ✓
 ├── Node 2 ✓
 └── Node 3 ✗
        ↓
   Replication
        ↓
   Node 4 ✓

Now:

Block A
 ├── Node 1
 ├── Node 2
 └── Node 4

The system has restored the desired replication level.


10. DataNode "Phones Home"

A DataNode periodically communicates with the NameNode.

Conceptually:

DataNode
    |
    | "Here I am"
    ↓
NameNode

If a DataNode was unavailable for some period and comes back, it can learn what state it needs to synchronize with the rest of the cluster.

This helps HDFS deal with entropy caused by failures and missing replicas.


11. HDFS Architecture Summary

                       Client
                         |
                 Metadata Request
                         ↓
                    NameNode
                         |
                  Block Locations
                         ↓
              ┌──────────┼──────────┐
              ↓          ↓          ↓
          DataNode 1 DataNode 2 DataNode 3
              ↓          ↓          ↓
           Block A    Block A    Block B

Remember:

NameNode = Metadata

DataNode = Actual Data


12. Now Distributed Computation

HDFS explains storage.

But Hadoop also needs to answer:

How do we run computation on this distributed data?

The classical Hadoop architecture introduced another master:

JobTracker

And worker-side processes:

TaskTrackers

The historical architecture looks like:

                    JobTracker
                         |
          ┌──────────────┼──────────────┐
          ↓              ↓              ↓
     TaskTracker     TaskTracker     TaskTracker
       + DataNode      + DataNode      + DataNode

This is the classic Hadoop MapReduce architecture.


13. JobTracker

The JobTracker is responsible for managing MapReduce jobs.

A client submits a job:

Client
  |
  | Submit MapReduce Job
  ↓
JobTracker

The job contains the Map and Reduce logic.

Historically, this might be packaged as a JAR containing the application code.


14. TaskTracker

Each worker machine has a TaskTracker.

The TaskTracker executes the work assigned to that machine.

JobTracker
     |
     ├─────────────┐
     ↓             ↓
TaskTracker     TaskTracker
     ↓             ↓
   Mapper         Mapper

In the classic Hadoop model:

DataNode + TaskTracker

exist on the same worker machine.

This is important because it enables data locality.


15. Complete Hadoop Computation Flow

Let's connect everything.

                         Client
                           |
                           | Submit Job
                           ↓
                      JobTracker
                           |
             ┌─────────────┼─────────────┐
             ↓             ↓             ↓
        TaskTracker   TaskTracker   TaskTracker
             |             |             |
          DataNode      DataNode      DataNode
             |             |             |
          Local Data    Local Data    Local Data
             ↓             ↓             ↓
           Mapper        Mapper        Mapper
             ↓             ↓             ↓
             └─────────────┼─────────────┘
                           ↓
                        Shuffle
                           ↓
                    Reducer Tasks
                           ↓
                         HDFS

16. Step-by-Step MapReduce Job

Suppose we want to count words in 100 TB of data.

Step 1 — Data already exists in HDFS

HDFS
 |
 ├── Block 1 → DataNode 1
 ├── Block 2 → DataNode 2
 ├── Block 3 → DataNode 3
 └── ...

Step 2 — Client submits MapReduce job

Client
  ↓
JobTracker

Step 3 — JobTracker distributes Map tasks

JobTracker
   |
   ├──→ TaskTracker 1
   ├──→ TaskTracker 2
   └──→ TaskTracker 3

17. Data Locality

This is one of the most important Hadoop concepts.

Suppose:

Block A
   ↓
DataNode 1

Hadoop tries to execute the mapper on or near DataNode 1.

DataNode 1
    |
    ├── Block A
    |
    └── Mapper

Instead of:

Block A
   ↓
Network
   ↓
Remote Server
   ↓
Mapper

The computation moves to the data.

Remember:

Hadoop tries to bring computation to the data, not data to the computation.


18. What Does the Mapper Do?

Suppose:

Data:
"The Raven Raven"

Mapper produces:

(raven, 1)
(raven, 1)

These intermediate key-value pairs are generated locally.


19. Mapper Writes Intermediate Data

The mapper produces intermediate data that will eventually participate in the Shuffle phase.

Conceptually:

DataNode
   |
   ↓
Mapper
   |
   ↓
(raven,1)
(raven,1)

The framework then handles the Shuffle.


20. Shuffle

Now Hadoop groups identical keys.

Suppose:

Node 1 → (raven,1)
Node 2 → (raven,1)
Node 3 → (raven,1)

Shuffle may move the data:

Node 1 ────┐
Node 2 ────┼──→ Network → Reducer
Node 3 ────┘

Then:

raven → [1,1,1]

21. Reduce

Reducer receives:

raven → [1,1,1]

and calculates:

1 + 1 + 1 = 3

Result:

(raven, 3)

The final output can then be stored back into HDFS.


22. Full Hadoop Data Flow

                 HDFS
                  |
            Distributed Data
                  ↓
          ┌──────────────┐
          │   JobTracker │
          └──────┬───────┘
                 ↓
       ┌─────────┼─────────┐
       ↓         ↓         ↓
    Mapper     Mapper     Mapper
       ↓         ↓         ↓
       └─────────┼─────────┘
                 ↓
              SHUFFLE
                 ↓
       ┌─────────┼─────────┐
       ↓         ↓         ↓
    Reducer    Reducer    Reducer
       └─────────┼─────────┘
                 ↓
                HDFS

23. Why Hadoop Can Scale

The developer accepts constraints:

Map
+
Reduce

Hadoop then handles:

  • Distribution

  • Scheduling

  • Data locality

  • Task execution

  • Failure recovery

  • Intermediate data movement

  • Result storage

So the developer doesn't need to manually coordinate hundreds of machines.


24. Complex Real-World Jobs

Real applications may require many MapReduce jobs.

For example:

Job 1
 ↓
Job 2
 ↓
Job 3
 ↓
Job 4
 ↓
Job 5

This becomes difficult to manage manually.

That's why higher-level APIs and workflow systems became important.


25. Cascading

Cascading is an example of a higher-level API that makes complex MapReduce workflows easier to express.

Instead of manually thinking about every low-level MapReduce operation:

Map → Reduce
Map → Reduce
Map → Reduce

you can work at a higher abstraction.

The underlying execution still ultimately becomes distributed computation.


26. Hive

Another important Hadoop ecosystem technology is Hive.

Hive provides a SQL-like interface for querying Hadoop data.

Instead of writing low-level MapReduce code:

Mapper
Reducer
Shuffle
...

you can express an analysis using SQL-like syntax.

Conceptually:

SQL Query
   ↓
 Hive
   ↓
Distributed Execution
   ↓
MapReduce / Hadoop
   ↓
Result

This is why Hive became important for analysts and developers who didn't want to write raw MapReduce programs.


27. Hadoop Distributions

Hadoop is open source and has historically been packaged and supported by companies providing:

  • Enterprise distributions

  • Support

  • Training

  • Management tools

  • Consulting

Examples historically included companies such as Cloudera and Hortonworks.

The important concept is not the vendor name but the fact that Hadoop developed a large commercial ecosystem around the open-source project.


28. When Should You Use Hadoop?

This is a very important design question.

Hadoop makes sense when you have:

1. Very large data

TB → PB → potentially beyond

2. Distributed processing requirements

You need many machines to process the data.

3. Batch-oriented workloads

You don't need every result immediately.

4. Relatively low data velocity

Data can be accumulated and processed in batches.


29. When Hadoop Is NOT a Good Choice

Case 1 — Data isn't very large

If your entire dataset fits comfortably on one machine:

100 MB / 10 GB / modest dataset

Using Hadoop may introduce unnecessary complexity.

Don't use distributed systems when you don't need distributed scale.


Case 2 — Very low latency requirements

Suppose:

User clicks
   ↓
System
   ↓
Result required in 10 ms

Traditional Hadoop MapReduce is not a good fit.

Why?

A MapReduce job has significant overhead:

  • Job setup

  • Scheduling

  • Task startup

  • Distributed coordination

  • Disk I/O

  • Shuffle

  • Result writing

So even a tiny computation can take considerably longer than the actual computation itself.


30. Hadoop Is a Batch System

Think:

                HADOOP
                   ↓
             Large Dataset
                   ↓
           Batch Processing
                   ↓
             Final Result

Not:

Event
  ↓
10 milliseconds
  ↓
Result

For real-time/low-latency workloads, technologies such as Spark or stream-processing systems such as Storm may be more appropriate depending on the problem.


31. Hadoop vs Database

Suppose you have:

Scenario A

100 TB historical sales data
Analyze last 5 years

Hadoop can make sense.

Scenario B

Customer purchases product
      ↓
Transaction must be recorded immediately
      ↓
Customer expects immediate response

A traditional transactional database is usually more appropriate.

The distinction is:

Hadoop → Large-scale batch analytics

Database → Transactional / low-latency workloads

32. HBase vs Traditional Database

HBase sits on top of HDFS and provides a database-like layer.

But the lecture's key point is:

If you are starting from scratch, HBase isn't automatically the database you should choose just because you have Hadoop.

It tends to make more sense when there is already a strong HDFS/Hadoop commitment and you need its particular access model.


33. Hadoop vs Spark vs Storm

This connects to your previous class.

TechnologyPrimary Strength
Hadoop MapReduceLarge-scale batch computation
SparkGeneral distributed computation, often faster/more flexible than classic MapReduce
StormReal-time stream/event processing
Traditional DBTransactional and low-latency workloads
HDFSDistributed large-file storage

Simple mental model:

Huge Historical Data
       ↓
    Hadoop
       ↓
    Batch

Complex Distributed Analytics
       ↓
     Spark
       ↓
Fast Distributed Processing

Continuous Events
       ↓
     Storm
       ↓
Real-Time Processing

34. Hadoop Architecture — Final Mental Model

                         HADOOP
                            |
          ┌─────────────────┴─────────────────┐
          ↓                                   ↓
         HDFS                             MapReduce
    Distributed Storage              Distributed Compute
          |                                   |
     ┌────┴────┐                         JobTracker
     ↓         ↓                              |
 NameNode   DataNodes                ┌────────┼────────┐
     |         |                     ↓        ↓        ↓
 Metadata   Data Blocks           TaskTracker ... TaskTracker
               |                     |             |
          Replication              Mapper        Mapper
                                     |             |
                                     └──────┬──────┘
                                            ↓
                                         Shuffle
                                            ↓
                                         Reduce
                                            ↓
                                           HDFS

⭐ Interview Questions to Remember

1. Why doesn't the client send data through the NameNode?

Because the NameNode handles metadata, while DataNodes handle the heavy data transfer. Sending all data through the NameNode would create a bottleneck.

2. What is data locality?

Running computation on or close to the node where the required data is stored.

3. Why does Hadoop replicate blocks?

For fault tolerance and availability when DataNodes fail.

4. What does JobTracker do?

In the classic Hadoop MapReduce architecture, JobTracker manages MapReduce jobs, schedules tasks, monitors execution, and handles failures.

5. What does TaskTracker do?

In the classic architecture, TaskTracker runs Map/Reduce tasks on worker nodes.

6. What happens during Shuffle?

Intermediate key-value pairs are partitioned/grouped by key and may be transferred across the network to the appropriate reducers.

7. Why is Hadoop not suitable for low-latency applications?

Because traditional MapReduce has significant job setup, scheduling, task, I/O, and shuffle overhead.

8. When should Hadoop be used?

When you have very large datasets + distributed processing + batch-oriented workloads.


⭐ Most Important Takeaway

Remember this sequence:

HDFS stores → NameNode knows where → DataNodes hold blocks → JobTracker schedules → TaskTrackers execute → Mapper processes local data → Shuffle moves/groups data → Reducer aggregates → HDFS stores the result.

One important historical note for interviews: JobTracker/TaskTracker describes Hadoop MapReduce v1. Modern Hadoop uses YARN, where ResourceManager/NodeManager replace that classic job/task-management architecture.