Of course it is possible to do with Apex. And, there are a variety of free and paid options for 3rd party tools that can de-duplicate or block creation of duplicate records (Salesforce Duplicate management, DupeCatcher, Dupeblocker/DemandTools, etc.). It really depends on how you can identify the duplicates in the first place.
For the declarative configuration route, if there was one field that would identify duplicates (like some type of external ID, you could set that ID field as unique in the setup, preventing the duplicates from loading.
For the Apex option, you could use a trigger to scan for potential duplicates based on your rules for identifying them, and either, block them from creation, or flag as potential duplicates for manual review, depending on your business requirements. Lastly, you could develop a scheduled batch job that would analyze the object for potential duplicates.
First step for you is to determine how to identify a duplicate, and what do do if a duplicate is being saved in the system. THen, you can move on to the "how" to detect and handle.