If you look at the "Related Article" from which you came, you will see that the Late 2009 iMac MUST be a 27-inch model, and the MacBook Air MUST be 2019 or older running no higher than macOS 10.15 Catalina.
Even if your equipment falls within the narrow hardware and software requirements, the amount of money required for Thunderbolt cables and adapter can approach the cost of a new good-quality external monitor. The free-standing external monitor has more advantages:
- Easier to set up
- More reliable
- Simple cabling
- Allows extended desktop (TDM only mirrors)
- Uses far less energy
Apple have abandoned Target Display Mode. They started its deprecation in Mid 2014 and threw the final shovelr of dirt in its face in early 2020. It's dead tech.
What remains are Apple's Network Screen Sharing
Share the screen of another Mac - Apple Support
and third-party solutions like Luna Display. Network screen sharing is laggy; I've not used Luna so can't say if the lag reamins.