Elixir’s ability to build fault-tolerant, distributed systems is one of its strongest features, utilizing the Erlang VM for seamless node communication, clustering, and fault tolerance. Understanding how to set up and manage distributed Elixir nodes, perform Remote Procedure Calls (RPC), and handle failures is crucial for building resilient applications. These 30 multiple-choice questions (MCQs) will help you dive deep into distributed systems concepts in Elixir programming.
MCQs on Distributed Systems in Elixir
Setting up Distributed Elixir Nodes
What command is used to start an Elixir node?
a) elixir --sname <name>
b) iex --name <name>
c) elixir --name <name>
d) iex --sname <name>
How do you connect two Elixir nodes together?
a) By using Node.connect/1
b) By using Node.link/1
c) By using Node.connect/2
d) By using Node.join/1
What does the --sname option in the iex command specify?
a) The short name of the node
b) The node’s IP address
c) The long name of the node
d) The node’s cluster type
Which command starts an Elixir node with a specific cookie for authentication?
a) iex --cookie <cookie_name>
b) elixir --cookie <cookie_name>
c) iex --name <name> --cookie <cookie_name>
d) elixir --name <name> --cookie <cookie_name>
What is the default cookie used when starting an Elixir node?
a) 1234
b) secret
c) abc123
d) No default cookie
How do you check if an Elixir node is connected to another node?
a) By using Node.alive?/1
b) By using Node.connect?/1
c) By using Node.status/1
d) By using Node.ping/1
What does the Node.list/0 function return?
a) A list of connected nodes
b) A list of nodes in the cluster
c) A list of all active processes
d) A list of available resources
What is the function used to stop an Elixir node?
a) Node.exit/1
b) Node.stop/0
c) Node.shutdown/0
d) Node.disconnect/1
Node Communication and Clustering
Which command can you use to see the status of all nodes in a cluster?
a) Node.status/0
b) Node.list/0
c) Node.cluster/0
d) Node.info/0
What is the primary communication protocol between nodes in a distributed Elixir system?
a) TCP/IP
b) HTTP
c) Erlang’s distribution protocol
d) WebSocket
Which of the following is necessary for two Elixir nodes to communicate with each other?
a) The nodes must be in the same local network
b) The nodes must share the same cookie
c) The nodes must be running the same version of Erlang
d) All of the above
How can a node in a distributed system join a cluster?
a) By using Node.join/1
b) By using Node.connect/1
c) By using Node.link/1
d) By using Node.add_to_cluster/1
Which function in Elixir allows for sending a message from one node to another?
a) send/2
b) Node.send/2
c) Node.call/2
d) GenServer.call/2
How can you monitor the connections between nodes in an Elixir cluster?
a) By using Node.monitor/1
b) By using Node.link/1
c) By using Process.monitor/1
d) By using Node.connect/1
What happens when a node is disconnected from a cluster in Elixir?
a) The node crashes immediately
b) The node continues running without any issues
c) The node may lose its state if not properly handled
d) The node automatically re-connects to the cluster
How can a node leave a cluster in Elixir?
a) By using Node.leave/1
b) By using Node.stop/0
c) By using Node.disconnect/1
d) By using Node.exit/0
RPC in Distributed Systems
What does RPC stand for in the context of Elixir?
a) Remote Procedure Call
b) Remote Parallel Computing
c) Reliable Process Communication
d) Runtime Process Control
How do you call a function on a remote node in Elixir?
a) By using Node.call/2
b) By using GenServer.call/2
c) By using RPC.call/2
d) By using Node.spawn/1
Which function is used to perform an RPC call in Elixir?
a) Node.call/2
b) Node.spawn/1
c) GenServer.cast/2
d) GenServer.call/2
What happens when an RPC call is made to a non-existing process on a remote node?
a) The node crashes
b) A timeout error is raised
c) The call is ignored
d) The process is spawned automatically
What is the function used to send an asynchronous RPC request in Elixir?
a) Node.async/2
b) Node.call/2
c) GenServer.cast/2
d) Node.spawn/2
How do you ensure that an RPC call is routed to the correct node?
a) By using the node name and process name
b) By using the IP address of the node
c) By using the node’s cookie for authentication
d) By using the process ID (PID) of the remote process
Can you use RPC calls to communicate with a remote process that is inside a GenServer on another node?
a) Yes, you can use GenServer.call/2
b) No, only local processes can be called via RPC
c) Yes, by using Node.spawn/1
d) Yes, but only if both nodes share the same cookie
What function can be used to manage timeouts in an RPC call?
a) GenServer.call/2 with a timeout option
b) Node.call/2 with a timeout option
c) Node.spawn/1 with a timeout option
d) Process.call/2 with a timeout option
Fault Tolerance in Distributed Systems
Which Elixir feature ensures that a node can continue running even when other nodes fail?
a) Supervisor trees
b) Process pools
c) Task supervision
d) GenServer retries
How does Elixir handle process crashes in a distributed system?
a) By automatically restarting the process
b) By logging the error and continuing
c) By sending a termination signal
d) By crashing the entire node
What is the purpose of :net_adm.ping/1 in Elixir?
a) To check if a node is reachable over the network
b) To ping a process inside a node
c) To monitor a node’s state
d) To test the system’s network performance
Which Elixir feature helps manage the failure of one node in a cluster?
a) Supervisor strategy
b) Task pool
c) Connection pool
d) Event-based retry mechanism
How can you monitor the health of nodes in a distributed system?
a) By using Node.monitor/1
b) By using Process.monitor/1
c) By using GenServer.monitor/1
d) By using Node.list/0
What happens when a node crashes in a distributed Elixir system with a supervisor?
a) The supervisor restarts the crashed node
b) The supervisor restarts the crashed process
c) The supervisor reports the crash but does not take action
d) The supervisor kills the other nodes in the cluster
Answers:
Qno
Answer
1
c) elixir --name <name>
2
a) By using Node.connect/1
3
a) The short name of the node
4
c) iex --name <name> --cookie <cookie_name>
5
d) No default cookie
6
a) By using Node.alive?/1
7
a) A list of connected nodes
8
b) Node.stop/0
9
b) Node.list/0
10
c) Erlang’s distribution protocol
11
d) All of the above
12
a) By using Node.join/1
13
a) send/2
14
b) By using Node.link/1
15
c) The node may lose its state if not properly handled
16
a) By using Node.leave/1
17
a) Remote Procedure Call
18
a) By using Node.call/2
19
a) Node.call/2
20
b) A timeout error is raised
21
a) Node.async/2
22
a) By using the node name and process name
23
a) Yes, you can use GenServer.call/2
24
b) Node.call/2 with a timeout option
25
a) Supervisor trees
26
a) By automatically restarting the process
27
a) To check if a node is reachable over the network