---
title: "Discussion on \"Finding cycles and hidden dependencies in go mod graph\" | Hashnode"
description: "Discussion on \"Finding cycles and hidden dependencies in go mod graph\". What a few graph algorithms can tell you about your Go module requirements"
url: "https://hashnode.com/posts/finding-cycles-and-hidden-dependencies-in-go-mod-graph/6ac78c67ebf43b6f18027dbb"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Finding cycles and hidden dependencies in go mod graph](https://hmdsefi.hashnode.dev/finding-cycles-and-hidden-dependencies-in-go-mod-graph?utm_source=hashnode&utm_medium=feed)

What a few graph algorithms can tell you about your Go module requirements

Oct 8 · 7 min read · hmdsefi.hashnode.dev  
Read the article

-   [#go](https://hashnode.com/tag/go)
-   [#golang](https://hashnode.com/tag/golang)
-   [#opensource](https://hashnode.com/tag/opensource)
-   [#devops](https://hashnode.com/tag/devops)

## Written by

[Hamed Yousefi](https://hashnode.com/@hmdsefi)

@hmdsefi · Dubai, UAE

  
[View profile](https://hashnode.com/@hmdsefi)

## Responses 3

Markdown supported · ⌘↵ to post

[Parsa Aftabi](https://hashnode.com/@parsaaftabi)

[Oct 9](https://hashnode.com/posts/finding-cycles-and-hidden-dependencies-in-go-mod-graph/6ac78c67ebf43b6f18027dbb/comment/6ac96489954062902cbd31ed)

Useful walkthrough. One sharpening: pair go mod graph with `go mod why <module>`. The graph shows you the edges, why tells you which of your imports actually pulls a module in, which is what you need when deciding what to cut. Also worth noting for readers: since Go 1.17 module graph pruning, the graph is shallower than it used to be. And a "cycle" in require directives is a version-selection quirk. True import cycles are still rejected by the compiler.

[Hamed Yousefi](https://hashnode.com/@hmdsefi)

[Oct 10](https://hashnode.com/posts/finding-cycles-and-hidden-dependencies-in-go-mod-graph/6ac78c67ebf43b6f18027dbb/comment/6ac96489954062902cbd31ed#reply-6aca11a40064a2d68f9ccc1e)

Thanks, good points. I agree on pairing the two. The "why" section touches on this: go mod why -m follows the package import graph, and the requirement graph shows which chain of go.mod files brought a module in. When you're deciding what to cut, the import chain is the one to act on.

The pruning note is a useful addition. Since Go 1.17, the graph leaves out the deeper requirements of modules that declare go 1.17 or later, so the same project can show a much smaller graph than it did on older Go versions. Worth keeping in mind when comparing graph sizes across projects.

And yes, the cycle in the article is a requirement cycle between the otel modules, which Go allows. An import cycle between packages is a compile error, so the compiler already catches that one.

[Parsa Aftabi](https://hashnode.com/@parsaaftabi)

[Oct 10](https://hashnode.com/posts/finding-cycles-and-hidden-dependencies-in-go-mod-graph/6ac78c67ebf43b6f18027dbb/comment/6ac96489954062902cbd31ed#reply-6aca298e19d143c3fef8e78f)

Glad it landed. And good confirmation on the otel requirement cycle. Exactly the kind that slips past you in a monorepo, since Go won't stop you from building one.
