---
title: "Stateful vs stateless; NFS architecture"
subject: "Distributed System"
chapter: 2
key: "semester_7/distributed_system:nfs-stateful-stateless"
source: https://www.bctengineer.com/q/semester_7/distributed_system/nfs-stateful-stateless
site: BCT Engineering
---

# Stateful vs stateless; NFS architecture

Distributed System · Chapter 2: Distributed Objects and File System

- Asked in: 2075 Chaitra, 2+6 marks
- Video: [Operating System Important Topics | Comparison between Stateless and Stateful File System](https://www.youtube.com/watch?v=oSpuw6kC0pI) — Easy Engineering Classes
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/distributed_system/nfs-stateful-stateless
- Whole chapter: https://www.bctengineer.com/md/semester_7/distributed_system/chapter-2

## Question

Compare stateful and stateless service. Describe the architecture and operation of SUN NFS with its services.

## Short answer

Stateful servers keep client state, complicating recovery; stateless servers keep no state, needing idempotent operations. Sun NFS uses a VFS layer, NFS client/server, and mount service. The client sends RPCs with file handles; the stateless server maps handles to local files and returns results.

## Answer

#### Stateful versus stateless service
| Point | Stateful service | Stateless service |
|---|---|---|
| Server memory | Keeps information about each client (open files, file pointers) | Keeps no client information |
| Request | Short; refers to a session or open file id | Longer; each carries file id, offset, count |
| Crash recovery | Complex; server must rebuild or clients must re-establish state | Simple; just restart |
| Client crash | Server must detect and clean orphaned state | No effect |
| Operations | Need not be idempotent | Must be idempotent (repeatable) |
| Performance | Fewer disk accesses, read-ahead is easier | More overhead per request |
| Locking | Easy to support | Needs a separate lock service |
| Example | AFS (callbacks), RFS | NFS (v2, v3) |

#### SUN NFS architecture and operation
**SUN NFS** (Network File System) is the most widely used distributed file service, developed by Sun Microsystems. It lets a client access remote files as if they were local, over an RPC-based protocol that is independent of the operating system, hardware and network.

**Architecture**

```text
 Client computer                       Server computer
 +-----------------------------+       +-----------------------------+
 | Application programs        |       |                             |
 |-------- UNIX kernel --------|       |-------- UNIX kernel --------|
 |    Virtual file system      |       |    Virtual file system      |
 |      |              |       |       |       |              |      |
 | +----v-----+  +-----v-----+ |       | +-----v-----+  +-----v----+ |
 | | UNIX     |  | NFS       | |       | | NFS       |  | UNIX     | |
 | | file     |  | client    | |       | | server    |  | file     | |
 | | system   |  |           | |       | |           |  | system   | |
 | +----------+  +-----+-----+ |       | +-----+-----+  +----------+ |
 +---------------------|-------+       +-------|---------------------+
                       |                       |
                       +<---- NFS protocol --->+
                              (RPC over UDP/TCP)
```

- **Virtual file system (VFS):** a layer in the kernel that decides whether a request is for a local file or a remote file and passes it to the UNIX file system or to the NFS client. It keeps a *v-node* for each open file; the v-node holds an i-node reference for a local file or a *file handle* for a remote file.
- **NFS client:** translates VFS operations into RPC requests to the server.
- **NFS server:** receives requests, identifies the file by its **file handle** (file system id, i-node number, i-node generation number), and calls the local file system.
- **Mount service:** a client mounts a remote directory into its local file tree. The server lists the file systems it exports in /etc/exports, and the client records each mounted remote directory in its mount table.
- **Automounter:** mounts a remote directory on first use.

**Operation**

1. The application issues a system call (for example read).
2. The VFS finds that the file is remote and calls the NFS client.
3. The NFS client sends an RPC (lookup, read, write, getattr, create, remove, mkdir, readdir...) over UDP/TCP using XDR encoding.
4. The NFS server's VFS finds the local file by the file handle, runs the operation on the local file system and returns the result.
5. The client caches the data (block cache) and attributes. Cache validity is checked by comparing timestamps; a cached entry is trusted for a freshness interval of about 3–30 seconds for files and 30–60 seconds for directories.

**Features / properties**

- **Access and location transparency** through mounting.
- **Stateless server:** each request carries all the information needed, so a crashed server restarts without recovery work; operations are idempotent.
- **Heterogeneity:** works with any OS that implements the protocol.
- **Caching:** read-ahead and delayed write for performance, with approximate (not strict one-copy) consistency.
- **Security:** the original version trusted the user id sent in the RPC; later versions use Kerberos.
- **Limited replication and migration support.**

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the key difference between stateful and stateless file services?
   A. A stateful server keeps per-client information (open files, file pointers); a stateless one keeps none
   B. A stateless server keeps a table of open files; a stateful one does not
   C. A stateful server needs longer requests than a stateless one
   D. Both keep state but only stateless saves it on disk
   Answer: A. Stateless servers hold no client information, so every request must be self-contained. (Key point: Server memory)

2. Which statement about crash recovery is correct?
   A. A stateless server recovers by just restarting; a stateful server must rebuild state or clients must re-establish it
   B. A stateful server recovers by just restarting
   C. Both need complex recovery of open-file tables
   D. A stateless server must detect and clean orphaned state of crashed clients
   Answer: A. Nothing needs rebuilding in a stateless design, whereas stateful servers lose session tables. (Key point: Crash recovery)

3. Why must operations in a stateless service be idempotent?
   A. Because the server must remember each client's file pointer
   B. Requests may be retransmitted and repeating them must give the same effect
   C. Because requests are shorter and refer to a session id
   D. Because idempotent operations make locking easy
   Answer: B. With retransmission and no duplicate memory, repeated execution must be harmless. (Key point: Idempotent operations)

4. Which pairing is correct?
   A. Stateless: short requests using a session id, as in AFS
   B. Stateful: long requests carrying file id, offset and count, as in NFS
   C. Stateless: longer requests carrying file id, offset and count, as in NFS (v2, v3)
   D. Stateful: no need to track clients, as in NFS
   Answer: C. A stateless request must say which file, where and how much; NFS is the standard stateless example. (Key point: Request size and example)

5. What does the Virtual File System (VFS) layer do in NFS?
   A. Decides whether a request is for a local or a remote file and passes it to the UNIX file system or the NFS client
   B. Stores the file data of remote clients on the server
   C. Encrypts all RPC messages between client and server
   D. Mounts remote directories automatically on first use
   Answer: A. The VFS sits in the kernel and routes each request, using v-nodes for local and file handles for remote files. (Key point: Role of VFS)

6. How does an NFS client check that cached data is still valid?
   A. The server sends an invalidation callback on every write
   B. Cached data is never checked and is always trusted
   C. Every read is re-fetched from the server
   D. By timestamp comparison, with a freshness interval (about 3 s for files, 30 s for directories)
   Answer: D. NFS gives only approximate consistency: caches are validated by timestamps after a short interval, not strictly one-copy. (Key point: Client caching consistency)

## Related in Distributed System

- [SUN NFS architecture and operation](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Asun-nfs-architecture) — Distributed System, chapter 2, asked 3×
- [DFS; stateless vs stateful services](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Adfs-stateless-stateful) — Distributed System, chapter 2
- [Stateful/stateless and DNS working](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Astateful-dns-example) — Distributed System, chapter 2
- [Need of naming; Sun NFS](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Anaming-nfs) — Distributed System, chapter 2
- [Stub, skeleton and NFS architecture](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Astub-skeleton-nfs) — Distributed System, chapter 2
- [DFS requirements and file service architecture](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Adfs-requirements-architecture) — Distributed System, chapter 2

## Related in other subjects

- [ISDN architecture, services and channels](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Aisdn-architecture-channels) — Telecommunications, chapter 8, asked 2×
- [Web services architecture; SOAP and WSDL roles](https://www.bctengineer.com/question.md?key=semester_7%2Fweb_technology%3Aweb-services-soap-wsdl) — Web Technology, chapter 8
- [Basic ISDN services and architecture](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Aisdn-services-architecture) — Telecommunications, chapter 8
- [Compare RISC and CISC architecture](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Arisc-vs-cisc) — Microprocessor, chapter 6, asked 4×
