Can Terraform Solve Circular Dependency Issues Between Microservices?

Hi everyone,

I’m currently working on a project where I have two microservices that are tightly coupled—they both require each other to be up and running during startup, leading to a circular dependency issue. Both services call each other right at initialization, creating a deadlock situation.

I’ve heard some suggestions that Terraform could potentially solve this problem by ensuring both services are started simultaneously on their respective nodes, but I’m not convinced this would fully resolve the issue at the application level.

My question is: Can Terraform, or any of its features, really address this circular dependency at the code level between microservices? Or is this something that needs to be solved by restructuring the services themselves, for instance by introducing message queues, service discovery, or other mechanisms?

I would appreciate any insights or experiences from those who have faced similar challenges.

Thanks in advance!

That right there is your problem, you have an impossible requirement that additional tooling cannot solve. There must be some way one service waits for the other, because there is no way to ensure they start at exactly the same instant.

That fundamental issue is the same when applied to Terraform, it needs an order with which to execute each resource, and a circular dependency can’t be resolved to a single ordering. You could theoretically set no dependency between the resources in the configuration, in which case Terraform might start them concurrently, but then you fall back to the problem that “concurrent” does not mean they start at the exact same instant, and the services can still fail.

2 Likes

Thank you for your answer.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.