Selena Gomez and her longtime songwriting partner Julia Michaels bonded over their failed relationships with their famous exes.

Michaels, 26, opened up about her professional relationship with the Lose You to Love Me hitmaker in a chat with Variety and confessed the pair soon realised they'd been through similar experiences when it came to romance.

“When (Gomez and I) first started working together (in 2013), it started as me writing the songs,” she shared. “I walked in to the session one day because she wanted to change some words to the song, and she was like, ‘We must be going through the exact same thing because you’re writing everything that I feel.’

"I was like, ‘Oh, cool, you had a s**tty ex-boyfriend too? Let’s go!'”

Gomez, 27, previously enjoyed a highly-publicised relationship with pop star Justin Bieber, while Michaels was in a relationship with singer Lauv, with whom she collaborated on their tune, There's No Way.

Michaels added she tries to draw upon her raw emotions regarding her relationships when penning new music, explaining: “That helps me figure out what I want to say lyrically.

“I write everything as if you’re talking to the person you’ve wanted to confront; if you could say it to somebody, why couldn’t you say it exactly how you would in a song?”