Carefully selected (more in next para) cyclic groups $\{g^0,g^1,g^a,..., g^b, ...\}$ are used because in these groups finding the discrete logarithm of a group element is computationally hard, i.e. determining $a$ from $g^a$ is hard. This enables Alice and Bob to share public keys ($g^a$ and $g^b$) and come up with a shared secret $g^{ab}$, while Eve who sees the public key cannot compute the secret key. For Eve not to determine $g^{ab}$ from $g^a$ and $g^b$, requires three conditions to be satisfied:
- Computing $a$ from $g^a$ is hard (the discrete logarithm problem), and
- Computing $g^{ab}$, given $g^a$ and $g^b$ is hard (the computational Diffie-Hellman problem), and
- $g^{ab}$ being totally random element in group $\Bbb G$ given $g^a$ and $g^b$, i.e. given $g^a$ and $g^a$, Eve's guess of $g^{ab}$ is at-best uniform random probability (the decisional Diffie-Hellman problem)
The carefully selected cyclic group is typically a prime-order subroup of $\Bbb Z_p^*$. Let $p=rq +1$, with $p$ and $q$ large primes (eg. $p$ 3072 and $q$ 256 bits). Then subgroup of $\Bbb Z_p^*$ of order $q$ is selected. In such a subgroup all three conditions above are conjectured to be met. (Ref: Section 8.3.3 and Chapter 9 of "Introduction to Modern Cryptography" by J. Katz and Y.Lindell).
The hard problem of factorizing two large prime numbers from their product cannot be used here, because the assumption for Diffie-Hellman is that Alice, Bob and Eve have the same information to start off with. So if Alice and Bob agree in public to the prime $c$ and share $ac$ and $bc$ with each other, Eve can easily factor $ac$ or $bc$, since Eve also knows $c$. The hard factoring problem works in RSA, because neither Eve nor Alice know the prime factors of $n$. So Alice can encrypt using public key and only Bob can decrypt, because only Bob knows the prime factors.