How does the website recognize the user buying preferences as soon as they visit the website?
When you first visit a website it tells your browser to save a
cookie on your computer which uniquely identifies you to the
website.
When you later visit the same website it asks your browser for
any cookies that the website had previously saved. The value of the
cookie that identifies you is looked up in the website's database
and it immediately knows your preferences, history, etc. from the
database entry on you.