Both services use the ActivityPub protocol, so to put it very simply the data format used by both services is the same, they just render it differently on your screen. Then they are pushing/pulling the data for posts and comments from other instances as users request it, e.g. by viewing this lemmy instance through Mastodon.
I’m always advocating for Signal, but I’m worried for the time their billionaire-backing eventually runs out.