How does blockchain.info determine when a payment is received?
What you're describing is one way to do it but there are much better ways. Take a look at https://bitlab.co/wallet which is an open source real-time wallet API that you can learn from. The back-end source that interfaces with the bitcoind service is at https://github.com/bitlabco/bitlab-nodejs