To soothen your ego, just know the below facts (it will help).
1. EVERYONE improves very quickly (with minimal effort) in the beginning, or when they start tennis. This is just because there is a lot of room for easy improvement (low hanging fruits), and there is no way to not improve. But as the time goes by, the amount of effort you have to put in to improve increases by a lot, and so you either stop improving, or even start fluctuating based on your other priorities in life (rec player level saturation).
2. Your opponent won against you most probably will be in the same level/situation once they reach same experience as you. (rec player level saturation).
3. EVERY dog has its day (or two). So just because someone won against you one day does not make him a better player than you.
Knowing the above will help and give a temporary relief, so that you can go home and sleep the pain of that loss.
Now the long term solution is, kill the ego. Just know that you are as vulnarable tennis player as everyone else whom you play with. They play with you because they think you are at their approximate level. Also if you feel like you are spending too much money on tennis, with no return, you can always stop doing that.
Everyone "thinks" they want to improve, but in reality, most rec players are not determined/motivated enough to put the work needed in a systematic way to grab those high hanging fruits (after the first few years of tennis, and fast improvement during that time). You either accept this and move on, or put the "real" effort to improve.
It feels embarrassing and disappointing to lose despite having more experience than him.