From time to time magento randomly returns 404 error on existing pages, If I refresh the page - it works. Is there any way to debug the issue? I suspect that the problem is caused by some extension, but does not know how to determine which one, because the error is not consistent and can occur only several times a day.
Start by disabling the extensions you consider can be causing the issue, you can do this by going to app/etc/modules, in this folder you will find xml files for each module, there just change
Then flush magento cache and check.
Once you identify the extension you can use xdebug to track the problem.
What is exactly giving you 404, cms pages, category pages, product detail page, etc?