It’s compulsory with a huge asterisk next to it.
If they call you in, it’s compulsory.
However, they call far from everyone, and there’s about 1001 things you can do to not get called for service if you really don’t want to.
First step is that you’re sent a form to fill out. Questions about your health and habits among other things. So. If you really don’t want to… Let’s just say they probably won’t be too interested in someone that (allegedly) smokes 1-2 pack of cigarettes a day.
Not to be confused with the Swedish concept of “Total Defense” (probably poorly translated). Should “total-defense” be called however. Everyone between 16 and 70 have to report in for war-duty. This doesn’t mean everyone is going into battle. But it means you have to be at service for the defensive effort of our nation. Could be administrative tasks, logistical, construction, anything really, depends on who you are and what your experience is. This is not something you can get out of. It’s one of your duties as a citizen
More is mentioned in this pdf if your curious. This one is in English.
I will highlight the most important part
https://www.msb.se/sv/publikationer/om-krisen-eller-kriget-kommer-pa-engelska/