The immune system is an incredible protection mechanism that employs dozens of types of cells that attack the invaders all the time. The immune system does not work only when you feel you’re ill, it works every second of your life. If it weren’t you would be dead by now.
How does the immune system work? When the bacterium invades the white cells attack them and try to eat them all. Then the memory cells will retain the info that defines the invaders so that any future attack will be easier to fend off.