Start by testing your connection — lag in online games is far more often a network problem than a hardware one. Run a speed test and check ping; if the numbers are poor, no amount of RAM will help.
If the hardware is genuinely the bottleneck, the priorities are a modern multi-core CPU, 8 GB or more of memory, and a dedicated graphics card. A current mid-range machine handles the vast majority of online titles comfortably.
Also worth checking: wired ethernet over Wi-Fi, and closing anything streaming or downloading in the background.