Press the sauté button on the instant pot and add the oil to the pot. Wait for the oil to get hot, then add the onions and cook for 15-20 minutes, stirring occasionally, until browned (keep the stirring to a minimum in the beginning to brown the onions faster. As the onions brown, stir more frequently).
Add the garlic and ginger and stir-fry for 1-2 minutes.
Stir the bottom of the pot to scrape off any brown bits, if you have trouble with this, turn off the instant pot and let the onions sit for a few minutes, then try to scrape again.
Add the carrots, apple and water to the pot and stir.
Place a trivet in the pot (this is the one I use) and then place unpeeled beets on top of the trivet (if the beets seem very large, you can cut them in half).
Secure the lid, close the pressure valve and cook for 15 minutes at high pressure.
Naturally release pressure (if the valve hasn't dropped on its own after 25 minutes, open to release any remaining pressure)
Remove the trivet and the beets from the pot. Once the beets are cool enough to handle, remove the peels (they should easily slide off). Put the beets back into the pot.
Blend the masala using a blender or ideally, an immersion blender.
Stir in the spices and mix well, then add the tamarind paste 1 teaspoon at a time, tasting the sauce until it reaches your desired level of tanginess (different brands can vary in sourness - I use and love this tamarind paste and feel that 3 teaspoons is perfect).
Once the masala is cool, I store it using this silicone mold which holds 1/4 cup of onion masala per mold.
If you'd like to make this on the stovetop, follow the directions above but rather than pressure cooking just cook the vegetables until tender and then blend. You'll want to peel and chop the beets if you make it this way.
I recommend the recipe as written but feel free to adjust the spices according to your diet.
If you can tolerate nightshades, feel free to add 1 tablespoon paprika and ¼ teaspoon cayenne along with the other spices.