Why my 2009 macbook pro is faster than my 2017 retina iMac?
Yes, the SSD is the main difference.

Your iMac has a 1TB 5400rpm SATA Hard Drive and this is what’s causing the bottleneck. The MacBook Pro, on the other hand, has a solid state drive that is multiple times faster. So, while the iMac may actually process things faster, loading apps and reading/writing data will be a lot slower. And, if it needs to use hard drive space when it needs more RAM, this will also significantly slow things down.

Achieving the same/better performance

Since your iMac has two Thunderbolt 3 (USB-C) ports that support speeds up to 40 Gbps (via Thunderbolt) and 10 Gbps (via USB 3.1 Gen 2), the easiest solution is to use an external SSD that’s connected via one of these ports and to install macOS instead. You would then use that drive as your main boot volume. 

However, you would need to ensure that:


it’s definitely an external SSD (and not just a hard drive)
it supports either Thunderbolt or USB-C (i.e. USB 3.1) as its interface


Both of the above are critical if you’re wanting to improve speed. Thunderbolt models are still quite expensive, but you'll find USB-C / USB 3.1 models at reasonable prices.

NOTE:  Do not get confused by USB 3 - this is not the same as USB 3.1. And remember, it needs to connect to one of the two Thunderbolt ports (not one of the USB ports).

Some examples of the types of external drives I mean are:


Samsung T5
SanDisk Extreme 510
G-Technology G-DRIVE mobile SSD


Once you have the drive you want, you will need to install macOS onto it and migrate your data.