I am working on an e-commerce website, where users can create a new product to sell. When a user creates a new product, that new product gets an auto-incremented Id, let's say 25, so the link for the new product would be:
Now I have sitemap generator service which runs every one hour and rebuilds the sitemap. In this scenario,
mysite/products/25 would be added to the site map.
Let's assume after 10 days, the product is sold and the user deletes the product. Now if any client clicks on:
mysite/products/25 they will be redirect to home page and an informational alert appears on top of the page saying: this ad has been removed.
But this deleted link still exists in the sitemap (for several minutes) until the my sitemap generator service recreates the sitemap and remove the link of the deleted product.
What happens if Goolge (or any search engine) read the sitemap and try to reindex the page and gets redirect to home page? Would it negatively affect my website ranking? If so, how should I build the the dynamic sitemap to avoid this problem?
It is always the same problem with this kind of business - it is too volatile for Google's index. That's why you shouldn't index your products - but only categories, which are stable.
I.e. include into sitemap a category "ssd drives" - it is always in index. Every ssd drive from your vendors will be published into this category. User who wants to buy ssd drive, searchs for it - Google guides him to your category, where he finds ssd drives (products) from all of your vendors. Yesterday there were 10 ssd drrives, today - just three (7 sold out), tomorrow - 8 (there are 5 new), and so on. But category remains always in index, and you will be never ever able to get your products into index, they will be alway to late.