Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 66 ยท Getting Started

OS Structure: Monolithic, Layered, Microkernel

Compare operating system designs: simple, monolithic, layered, microkernel, modular and hybrid kernels, with trade-offs in speed, safety and flexibility and a crash demo.

An operating system is millions of lines of code. How should it be organized? Should the file system, network stack and device drivers all live inside one giant program, or be separate pieces that talk to each other? The answer decides how fast the system is, how easily it can be extended and, importantly, what happens when one component has a bug.

This lesson compares the classic designs: simple, monolithic, layered, microkernel, modular and hybrid. You will see why Linux, Windows and macOS each chose differently, and run a small experiment that shows the speed versus safety trade-off.

Two ends of a spectrum

Monolithic Everything in one kernel program.
Microkernel Tiny kernel, services outside.

Real systems sit somewhere between the two.

1 / 2

Simple structure

Early systems such as MS-DOS had no clear layers: application programs could call low-level routines and even write to hardware directly. This is small and fast, but a single faulty program could crash the whole machine, because there was no real protection between parts. It works on tiny devices; it does not scale.

Monolithic kernel

In a monolithic kernel, all the OS services (scheduler, memory manager, file systems, network stack, drivers) are compiled into one large program that runs entirely in kernel mode and shares one address space. Components call each other as ordinary functions, which is very fast. Traditional UNIX and Linux are monolithic.

Advantages: speed and simplicity of calls. Disadvantages: a bug in any driver can crash the entire system, the code base is huge and hard to maintain, and adding a feature means rebuilding or carefully loading code into the kernel.

Layered approach

A layered system divides the OS into levels: layer 0 is hardware, the top layer is the user interface, and each layer only uses the layer directly beneath it.

flowchart TB
    L5["Layer 5: user programs"]
    L4["Layer 4: I/O buffering"]
    L3["Layer 3: device drivers"]
    L2["Layer 2: memory management"]
    L1["Layer 1: CPU scheduling"]
    L0["Layer 0: hardware"]
    L5 --> L4 --> L3 --> L2 --> L1 --> L0

Each layer hides the details of the layers below it.

Layers make debugging easy (test layer 1, then layer 2 on top of it) and enforce clean interfaces. The problem is that it is hard to decide the ordering (the memory manager may need disk I/O, but the disk driver needs memory), and each request passes through many layers, which costs time. Pure layering is rare; layering within components is common.

Microkernel

A microkernel keeps only the bare minimum in kernel mode: low-level address-space handling, basic scheduling and inter-process communication (message passing). File systems, drivers, and network stacks run as separate user-space servers. When an application wants a file, it sends a message to the file server, which sends a message to the disk driver server.

flowchart LR
    App["Application"] -- "message" --> FS["File server (user mode)"]
    FS -- "message" --> Disk["Disk driver (user mode)"]
    App -. "all messages go through" .-> K["Microkernel (kernel mode)"]

Messages pass through the microkernel, which only provides IPC, scheduling and memory basics.

Advantages: if the audio driver crashes, only that server restarts; the rest of the system keeps running. The kernel is small enough to be formally verified, and the system is easy to extend. Disadvantages: more message copies and mode switches make it slower. Examples are QNX, MINIX 3, seL4 and the Mach kernel that influenced macOS.

Modular kernels

A modular kernel is monolithic but lets you load and unload pieces called loadable kernel modules at run time. Linux does this with modprobe for drivers and file systems. You get the speed of monolithic code with some of the flexibility of a microkernel (but a faulty module can still crash the kernel, because it runs in kernel mode).

Hybrid kernels

Hybrid designs borrow from both worlds. Windows NT and macOS (XNU) start from a microkernel-like structure but run many services in kernel mode for performance. They are practical compromises rather than pure designs.

Design Examples Speed Fault isolation Extensibility
Simple MS-DOS Fast None Poor
Monolithic Linux, classic UNIX Very fast Poor Good with modules
Layered THE system, parts of others Medium Medium Medium
Microkernel QNX, MINIX 3, seL4 Slower Excellent Excellent
Hybrid Windows NT, macOS Fast Medium Good

Experiment: call cost and crash isolation

The first demo mimics a request that needs three services. In the monolithic version each service is a function call. In the microkernel version each hop is a message that is copied through a queue managed by "the kernel". The numbers are tiny because Python is the same in both, but the relative extra work is what the design costs.

Python Function calls vs. messages

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The second demo shows why anyone accepts that cost. A "driver" crashes with an exception. In the monolithic model the exception escapes into the kernel and the whole system goes down. In the microkernel model the failure is contained in the server, and the kernel restarts it.

Python What a crashing driver does

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Which design is "best"?

None is best in general. Linux's monolithic design is fast, and its huge community keeps it stable. Safety-critical systems such as cars and aircraft prefer microkernels such as QNX and seL4. General desktop OSes compromise with hybrids. Another modern idea is moving risky code out of the kernel (user-space drivers, eBPF sandboxes) to get isolation without full message-passing cost.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which kernel design keeps file systems and drivers as separate user-space servers?

    A microkernel keeps only the minimum in kernel mode and runs other services as user-space servers that communicate by messages.
  2. 2. Why is a monolithic kernel usually faster than a microkernel?

    Direct function calls inside one address space avoid message copying and extra mode switches.
  3. 3. What is a loadable kernel module?

    Modules give a monolithic kernel flexibility: drivers and file systems are loaded on demand.
  4. 4. Windows NT and macOS are usually described as which kind of kernel?

    They mix microkernel ideas with monolithic performance shortcuts.
  5. 5. What is the main drawback of strict layering?

    Each layer adds overhead, and real services depend on each other in circles that make a strict order awkward.

Summary

  • Simple systems have no protection; monolithic kernels put everything in kernel space for speed.
  • Layered designs are clean but slow and hard to order; microkernels isolate services at the cost of messages.
  • Modular kernels load code on demand; hybrid kernels (Windows, macOS) compromise.
  • The trade-off is always speed versus fault isolation versus flexibility.

Next: What Is a Process?