Summary - Distributed systems
- Node.js course
- Expert
- Lesson 36/47
- 5 min
Combine CAP, consensus and tracing to write a distributed service.
Summary - Distributed systems
In this group we saw the core concepts of distributed systems: CAP theorem, consensus, distributed tracing, event sourcing and CQRS. Each shapes a distributed Node.js application.
CAP theorem forces a choice between consistency and availability during a partition. Consensus (Raft/Paxos) makes nodes agree on one value. Distributed tracing (OpenTelemetry) ties a request's path with a trace ID. Event sourcing builds state from immutable events. CQRS separates command and query models. In the final lesson we combine them in a report function.
The report function
The final task combines all distributed system concepts into one report. The distributedReport() function joins five info strings with ' | '. Output: CAP: AP | consensus: Raft | tracing: OpenTelemetry | event sourcing: replay | CQRS: split.
This report summarizes five core concepts in one string: the CAP choice (AP), the consensus algorithm (Raft), the tracing standard (OpenTelemetry), the event method (replay) and the CQRS split. Inside the function you place each piece in a variable, then join them with +. This lets you see what you learned on the console; you model the architecture without standing up a real distributed system.
Practice Write the distributed systems report
Write function distributedReport(). Define const cap = 'CAP: AP', const cons = 'consensus: Raft', const trace = 'tracing: OpenTelemetry', const es = 'event sourcing: replay' and const cqrs = 'CQRS: split'. Return cap + ' | ' + cons + ' | ' + trace + ' | ' + es + ' | ' + cqrs. Print console.log(distributedReport()).
Starter code
// Write the distributedReport function
// Join five info strings with ' | ' and return
// Call and print
// write hereSample solution
function distributedReport() {
const cap = 'CAP: AP';
const cons = 'consensus: Raft';
const trace = 'tracing: OpenTelemetry';
const es = 'event sourcing: replay';
const cqrs = 'CQRS: split';
return cap + ' | ' + cons + ' | ' + trace + ' | ' + es + ' | ' + cqrs;
}
console.log(distributedReport());Expected output
CAP: AP | consensus: Raft | tracing: OpenTelemetry | event sourcing: replay | CQRS: split
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which three guarantees does CAP theorem balance?
- Consistency, availability, partition tolerance Correct answer
- Consistency, availability, speed
- Consistency, security, cost
- Speed, cost, security
Explanation: CAP: consistency, availability, partition tolerance.
2 Match each concept to its role
| Term | Meaning |
|---|---|
CAP |
Choice during partition |
Raft |
Consensus algorithm |
OpenTelemetry |
Tracing standard |
CQRS |
Command and query split |