I'm new to modding Factorio (and modding in general), but have a lot of experience with software development. Super excited to get started on modding Factorio, I have played for around 800 hours and getting into mods feels like the next step in automating everything

I'm still trying to wrap my head around some of the basics regarding modding, so please bear with me. Essentially I'd like to understand how to best tackle code that needs longer than 1/60 seconds to run. From what I've understood and observed, the game will start to lag and slow down if I do any performance-intense computations in the on_tick handler.
Now from my general programming experience, I would to start a background thread and regularly communicate with that thread. But from what I've understood so far from reading tutorials, docs and other posts, this would probably cause multiplayer desyncs and therefore multithreading is not enabled? My second idea was be to use coroutines, which would allow to build concurrency without multithreading, but apparently these are also disabled for the same reason?
Now I'm wondering how to generally tackle these kind of things. I've looked at a couple of mods and it seems that many mods basically implement state machines that handle a single state per tick and then do a state transition for continuing on the next tick. But that still requires you to decompose your code into meaningful "steps", right? Are there any tips on that? Also how can I ensure that my steps actually complete within a single tick's time. Are there any approaches of tracking the time during your code and deciding whether you can continue doing stuff, or whether you should suspend and wait for the next tick? Are there any libraries that can help with monitoring/debugging these runtime/latency things?