When the bolsheviks created various SSRs under USSR how did they decide on the borders between them? I thought that maybe they based them on the teritorial division of the Russian Empire, but when I looked at the map of oblasts in 1914 I saw some differences. Because of the recent events I'm mostly interested in Ukraine's eastern and northern borders but I'm also curious if there was some general rule that was followed.
This really varied by region, as each republic had it's own unique set of circumstances. I'll note each of the 15 republics that existed at the dissolution in 1991, and some general comments at the bottom:
Russia - Effectively what was not separated into a different republic remained within the Russian SFSR, so no explanation required.
Belarus - A Belarusian puppet state was formed in 1918 by the Germans in the aftermath of the Treaty of Brest-Litovsk, and this formed the basis of the Belarusian SSR. It was greatly expanded in the decades afterwards though, gaining territory at the expense of both Russia and Poland (who lost their eastern territory in the aftermath of the Second World War).
Ukraine - Like Belarus, a puppet Ukrainian state was set up by the Germans, though the Ukrainians tried to keep it going after the Germans left. That didn't exactly work as the Bolsheviks invaded, as did the newly formed Polish state. It was also expanded at the expense of Poland after 1945, and Crimea was transferred from Russia to Ukraine in 1954, as well. The Donbas, the region that Russia and Ukraine have been fighting over since 2014, was incorporated into Ukraine from the start.
Armenia, Azerbaijan, Georgia - All three were independent in 1918, and were conquered by the Red Army in 1920 and 1921. They largely retained their pre-annexation borders, with some minor adjustments.
Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Uzbekistan - Collectively Central Asia was one autonomous region in 1918, Turkestan. This was quickly broken up into the Kirgiz Autonomous Republic (what became Kazakhstan and Kyrgyzstan), and the Turkestan Autonomous Republic. In 1924 they were further delineated, though the five republics were not all fully upgraded to union status until 1936 (when Kyrgyzstan was broken off from the newly-renamed Kazakh republic).
Moldova - Parts were originally in Ukraine as an autonomous republic, but when the Soviets annexed Bessarabia and Bukovina from Romania in 1940 (part of the Molotov-Ribbentrop Pact with Nazi Germany) they created a full union republic.
Estonia, Latvia, Lithuania - All three became independent in 1918, and largely retained their borders throughout the interwar years. They were annexed by the Soviet Union in 1940 (also part of the Molotov-Ribbentrop Pact), and then invaded by Germany in 1941 and occupied until the Soviets re-invaded in 1944. I believe Estonia and Latvia retained their borders, while Lithuania gained some territory courtesy of Poland in 1945.
At the times the Bolsheviks were setting borders, they did try to follow the facts on the ground as it related to ethnicity (or nationality, to use their term): the goal was to have most of the titular national group in their republic, so that Belarus would be largely Belarusian, Ukraine mainly Ukrainian, and so on. This proved difficult for a variety of reasons, both in the west (Belarus, Ukraine) and Central Asia: the peoples in both regions had a limited concept of a national identity, in that Belarusians didn't see themselves as Belarusian, for example. Going by language spoken didn't really work either: Kazakh and Kyrgyz, for example, are mutually intelligible, varieties of Uzbek and Turkmen were very similar, while in Belarus and Ukraine, people used different languages depending on the circumstances (Belarusian, Ukrainian, Russian, Polish, Lithuanian, Yiddish were all used in the region for certain things).
Ethnographers were used to try and set out where national groups lived, but this was a challenging task, and in part spurned development of codified languages for many peoples (Turkmen, for example, was given a set standard for the first time, while Uzbek was arguably created as distinct language). Even so, issues remained, and large numbers of peoples remained in the "wrong" republic afterwards, despite efforts to rectify that.
I realize this doesn't fully touch on your question about Ukraine, and I do apologize for that, but I hope it can give some idea on how complex this process was. That said, I can offer some reading on the matter, which may help clarify things:
For the more general look at these two books:
Empire of Nations: Ethnographic Knowledge and the Making of the Soviet Union by Francine Hirsch (2005). This looks at the ethnographers tasked with identifying the national groups in the Soviet Union, and then the efforts on how to sort them, including the delineation in Central Asia (Hirsch doesn't focus too much on the European side of things though).
The Affirmative Action Empire: Nations and Nationalism in the Soviet Union, 1923-1939 by Terry Martin (2001) is something I recommend a lot in my answers, because it really is that authoritative. Martin also focused on Ukraine in his research, so touches on the region quite a bit (though not so much the Donbas).
For more specific regions, the following are good:
Tribal Nation: The Making of Soviet Turkmenistan by Adrianne Lynn Edgar (2006). This was the first to look at the creation of one of the Central Asian states (there are also now books on Tajikistan and Uzbekistan, and I believe both Kazakhstan and Kyrgyzstan have something related to the topic, but can't confirm that), and my favourite. Edgard takes the policies mentioned in both Hirsch and Martin and examines the formation of Turkmenistan, effectively a case study. It's really interesting.
Belarus: The Last European Dictatorship by Andrew Wilson (2012). This is really two books in one: a history of the territory of Belarus, and then a look at the post-1991 state. This historic side is really good, as Wilson gets into the Bolshevik efforts to create a Belarusian state, and then expand it to fit their needs.
For Ukraine, I'm embarrassed to say I can't think of a solid book that would fit this. There are obviously several out there, as the events of 2014 really helped that out (and I'm sure we'll see a similar output in the coming years). With that in mind, I will suggest going with The Gates of Europe: A History of Ukraine by Serhii Plokhy (2021). Plokhy is Ukrainian, and a solid historian, and while I have not read this book, I know Plokhy touches on the era a bit, and would think he gives it a solid analysis.