The actor who played Garak in DS9 was Andrew Robinson. When he got the acting role, he wrote 200 pages of Garak's backstory. His use of this as a guide for his acting is probably a big reason why Garak's character has so much depth.
Most of that backstory was officially canonised by the head Trek writers. Robinson used it to write a novel, A Stitch in Time, in which Garak writes an autobiographical letter to Julian Bashir.