I was taught that the person going into shul gets right of way. (And not the person exiting)
And that a person carrying a sefer also has the right of way
Looking for the source of these halachos, (someone asked me)
It would seem (although I don’t know of a clear source for this rule), that being that entering a Beis Hakeneses is a Mitzvah, it is therefore a Mitzvah to rush to fulfill it, and is forbidden to rush to leave it (Orach Chaim 90:12).
Therefore, the earlier we get a chance to fulfill a Mitzvah, and the longer we get to hold on to the Mitzvah, the better - even for one more second!
And it is for this reason, that when Yom Tov falls out on Motzaei Shabbos, we first usher in Yom Tov - by making Kiddush, and only afterwards do we usher out Shabbos, by making Havdalah (Pesachim 103a, see Rashbam) - in order to hold on to it as long as possible - even for one more minute! (Based on the general rule of: “עַיּוֹלֵי יוֹמָא, כַּמָּה דְּמַקְדְּמִינַן לֵיהּ עֲדִיף. אַפּוֹקֵי יוֹמָא, כַּמָּה דִּמְאַחֲרִינַן לֵיהּ עֲדִיף” which means: with regards to the arrival of the day, the earlier we usher it in - the better; and with regards to it’s departure, the more we can postpone it - the better (Berachos 52a; Pesachim 105b)
A good place to look for information regarding the first part of your question may be the gemara in Sanhedrin 32b about two boats or two camels (if I remember correctly) who arrive at a narrow passageway coming from opposite directions, the gemara briefly discusses which one has priority. If I recall correctly, there is very little literature on this sugya, but the sefer who speaks the most on it is the Prisha (look in the Ein Mishpat for the mareh makom).
As for the second part of your question, the Darkei Moshe in Y"D siman 282 (אות א) brings from the Maharil that one carrying seforim has priority when going through a doorway.
I hope this was helpful.