There's presumably bot accessing media and mautic registers new anonymous contacts. Thus, the contact ID builds up so quickly

Are you getting a lot of the same IP or is it just one ip logging one hit…I am getting tons of IPs that are visitors anonymous (not bots based on the useragent) when Mautic should have placed all the same IP in one record…they are making a new record for each one… sometimes 50-60 in a row…killing my db… Also you can montior the useragent yourself to see if they are bots or non browsers…
Be careful with the blocking and deleteing… since if you confirm they are browsers and the keep hitting your normal pages and the hit like 2-3 hits a min… most likely they are leads and you will kill a ton of leads if you start auto deleting… So be careful.
I am working on several other solutions right now…will let you know… keep us informed if you are not able to solve it… I am pretty sure many of us have this problem and do not even know about it.