You're assuming a $500k house price? That's quite a bit above the median in the US. The median is closer to $200k, which would be $12k for the real estate agent fees (assuming you don't use redfin, of course). And of course you can price that into your sale price.
All of which is to say that optimal housing strategy depends _very_ strongly on the realities of the local market. Buying a house for $200k on a $50k salary is quite different from buying a house for $1.2 million on a $200k salary...