You will given a real lowball offer when you try to get back because you would be really vulnerable at the point. I know one of my seniors who did this - he did his SDE stint for 2 years, left to try UPSC for 2 years, couldn't crack it, applied for every role but companies were sceptical of his work ethic if he won't try to pursue a 3rd attempt after joining so he was lowballed and given SDE-1 offer even after 2YoE. He now has completed 1 year with the company and still waiting for promotion to SDE-2.
Your career trajectory will really be affected by such a career gap because it's not like a sabbatical where you are working on improving your skill/health. You are essentially questioning your career choices and attempting to do something risky. You lose faith from employers because of this move.
I would strongly suggest to reflect and think why you want to pursue UPSC/PSC. And you need to be answerable for the fact why did you leave a good high paying job at Microsoft to be a civil servant.
In a nutshell, it's not hard to get back to tech after such a gap but be ready to accept lowball offers.