liveBook · Manning

Protocol

As explained in Functional Design and Architecture: Examples in Haskell

A communication protocol is a defined set of rules and message formats governing interactions between communicating software components.

A communication protocol defines the requests and responses that independent components exchange. In an actor-based simulation, it hides the underlying environment and becomes the contract that lets each actor interact without knowing whether it runs against a real subsystem or a simulator. section 8.1.1

The protocol separates domain logic from orchestration. Spaceship parts can run as independent lightweight threads while the simulator controls their lifetimes and interactions invisibly. The same control scripts can therefore describe both real subsystems and simulated actors. section 8.1.1

A request–response protocol must address several practical concerns:

  • Define the messages exchanged by the requester and responder. section 8.1.3
  • Coordinate concurrent access so a request receives the corresponding result. section 8.3
  • Avoid protocols whose broad request and response types permit invalid pairings, such as receiving a reversed string after requesting a square. section 8.1.3
  • Move to message queues or STM when a large MVar-based model becomes difficult to express or maintain. section 8.3

MVar Request–Response

A pipe pairs an MVar for requests with an MVar for responses. The requester puts a value into the request MVar and waits for a response; a worker repeatedly takes the request, applies a function, and puts the result back. A FizzBuzz processor and generator use this arrangement to exchange results across two threads. section 8.1.3

Figure 8.2 Real environment and virtual environment

Compare the real environment with the virtual environment that the protocol allows actors to treat identically. section 8.1.1

Figure 8.5 The MVar Request–Response pattern flow

Trace the flow from request submission through worker processing to the returned response. section 8.1.3

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Defines contracts and demonstrates an MVar implementation, while stopping short of prescribing one response to invalid messages.
Examples
Uses spaceship actors, real-versus-virtual environments, FizzBuzz workers, and mismatched calculation responses.
What it assumes
Assumes threads and actor interactions, while introducing the protocol as an abstraction over the underlying environment.
What you can do after
Build it from scratch with MVars, request–response workers, and typed request and response data.
How it connects
Connects protocols with actor models, concurrency, MVars, message queues, STM, and domain-specific languages.

Also explained in

Compare how 3 books explain protocol →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.