up to 1 mm needle it doesn't hurt at all, the pain is like when you get rash, thats it. But bigger needle are really painful and blood may ooze out from area of application.
How it works is that, the dermaroller has lots of micro needles which when rolled on the scalp/hairline creates lot of micro holes on the skin and as like any other injured area on our body blood circulation increases at the area of application and increases blood circulation helps hair growth. I dunno about the hair growth but it really does increases the blood flow you literally feel your head beating.
But the downside of dermaroller is that it is only good for hairline or you need to shave your head to use it all over the scalp because the roller tangles in hair. Better option is dermastamp (thanks to
@AnxiousAndy for telling me about that) but thing is it is very much expensive than a dermaroller. But as for the hairline and front part dermaroller works great.