liveBook · Manning

Circular dependency

Also called cyclic dependency

A circular dependency is a dependency relationship in which a chain of direct or indirect dependencies eventually returns to an earlier participant, forming a cycle.

How 7 Manning books explain it

100 Java Mistakes and How to Avoid Them

A circular dependency is a dependency cycle in which class initialization directly or indirectly requires initialization of a class that depends back on the original class.

How it is used
Warns against initialization-time dependency cycles that expose null state or deadlock concurrent Java code.
How deep it goes
Explains field ordering, class-initialization locks, enum construction, and implicit switch behavior; defers broader dependency-design techniques.
Examples
Uses mutually initializing classes, parallel construction of A and B, jstack output, mutually referring enums, and an enum constructor switch.
What you can do after
Diagnose/debug with jstack class-initializer frames and recognize initialization cycles that can yield nulls or deadlock.

Read how 100 Java Mistakes and How to Avoid Them explains circular dependency →

Go by Example

An import cycle is a circular dependency among Go packages that prevents the package import graph from being acyclic.

How it is used
Prevents compile-time import failures while organizing maintainable Go services into packages with explicit dependency directions.
How deep it goes
Defines the error and works through layered package organization, while deferring interfaces and later service packages.
Examples
Uses mutually importing http and net packages, then a link core, link/rest API, linkd server, and alternative CLI tools.
What you can do after
Apply it by arranging focused Go packages so higher-level services import foundational packages without reverse dependencies.

Read how Go by Example explains circular dependency →

AI-Powered Developer: Build software with ChatGPT and Copilot

A circular dependency is a dependency relationship in which two or more modules or components depend on one another directly or through an intermediate dependency.

How it is used
Diagnoses import or instantiation failures discovered while creating unit tests for interconnected Python classes.
How deep it goes
Defines direct and indirect cycles, demonstrates their failure point, and sketches decoupling fixes without detailing broader dependency-management patterns.
Examples
Uses a visitor, Asset, FundingDetails, and DepreciationStrategy cycle, then shows revised class references.
What you can do after
Diagnose/debug with unit-test failures and reduce cycles by removing direct class instantiation or references.

Read how AI-Powered Developer: Build software with ChatGPT and Copilot explains circular dependency →

Acing the Frontend Interview

A circular dependency is a dependency relationship in which modules directly or indirectly import one another in a cycle.

How it is used
Frames module-cycle behavior as an interview-relevant maintainability and initialization concern.
How deep it goes
Explains initialization order and incomplete imports, but stops short of showing a refactoring procedure.
Examples
Uses mutually importing modules and an imported value accessed before dependency initialization completes.
What you can do after
Evaluate module cycles and explain why initialization can produce incomplete or undefined imported values.

Read how Acing the Frontend Interview explains circular dependency →

Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

A circular dependency is a dependency relationship in which a chain of resources forms a closed cycle, causing each resource to depend directly or indirectly on another resource in the same chain.

How it is used
Diagnoses Terraform planning failures caused by resource relationships that cannot be ordered.
How deep it goes
Defines cycles, demonstrates a three-resource failure, and gives a variable-based workaround without detailing broader resolution tools.
Examples
Uses authentication and logging services, three null_resource instances, a Cycle plan error, and a shared build_id variable.
What you can do after
Diagnose Terraform cycle errors and refactor shared values into variables or local values to remove unnecessary resource dependencies.

Read how Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu explains circular dependency →

Go in Action, Second Edition

A circular dependency is a dependency cycle in which packages or modules depend on one another directly or through an intermediate chain.

How it is used
Uses package dependency rules to guide project organization and separation of concerns.
How deep it goes
Defines direct and indirect cycles and compiler rejection, but gives no code-level refactoring procedure.
Examples
Uses package A and B dependency cycles plus a directory structure containing domain, storage, API, and worker modules.
What you can do after
Diagnose compiler-rejected package cycles and organize executables, shared libraries, and internal implementation packages.

Read how Go in Action, Second Edition explains circular dependency →

Grokking Software Architecture

A cycle in which components depend on one another, directly or through other components, forming a closed dependency path.

How it is used
Warns against upward dependencies between layers when preserving replaceability and testability.
How deep it goes
Explains a cycle’s brittleness and an orchestration alternative, stopping at architectural guidance rather than implementation details.
Examples
Uses a repository that calls the UI directly to show upward coupling and its testing costs.
What you can do after
Diagnose brittle layer dependencies and route notifications through the Application Layer after infrastructure returns data.

Read how Grokking Software Architecture explains circular dependency →

Also covered in

What to know first

Related concepts

Questions about circular dependency

What is circular dependency?

A circular dependency is a dependency relationship in which a chain of direct or indirect dependencies eventually returns to an earlier participant, forming a cycle.

Which Manning books explain circular dependency?

100 Java Mistakes and How to Avoid Them, Go by Example, AI-Powered Developer: Build software with ChatGPT and Copilot, Acing the Frontend Interview, Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu, Go in Action, Second Edition and Grokking Software Architecture.

What should I know before learning circular dependency?

Manning books that teach circular dependency usually introduce dependency injection, HTTP and package first.

What is the difference between circular dependency and directed acyclic graph?

A circular dependency is a dependency relationship in which a chain of direct or indirect dependencies eventually returns to an earlier participant, forming a cycle. A directed acyclic graph is a graph whose edges have directions and contain no directed cycles.

What is circular dependency also called?

Circular dependency is also called cyclic dependency.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.