When traveling by train from Tbilisi to Baku, there are two border checkpoints (one in Georgia, and one in Azerbaijan) - the total border crossing procedure can take around 2 hours (an hour for each side) and you can stay inside the train during the checkups.
In this article, I'll share some notes from our latest trip to Baku from Tbilisi by train in the start of August 2019
Tbilisi - Baku by Train Ticket Information
It takes about an hour for the train to reach Georgia / Azerbaijan border at Gardabani. Police officers (border guards) will enter the train, collect passports and check if you have Azerbaijani e-visa.
Cold drinks on the Gardabani border checkpoint
During the border checkups toilets are closed inside the train. While in Georgian side you are allowed to left the train and try some cold drink at a lonely kiosk or visit really nasty though free toilet.
Georgian side is not checking customs (obiviouly when departing Georgia) - just e-visa and passports.
Baku - Tbilisi train
Passports are brought back to the train, and the train departs for the Azerbaijan border checks at Boyuk Kasik.
Again, this time Azerbaijani border guards enter the train - every passenger is asked if he has been to Armenia, and if the answer is yes, the next question is about Nagorno-Karabakh. It turned out I have been to Armenia some 4 times (never been to Nagorno-Karabakh though).
You won't be allowed to enter Azerbaijan if you have been to Nagorno-Karabakh
It's not a problem having Armenian border stamp in your passport, as long as you haven't been to Nagorno-Karabakh.
Also border guards are asking about goods to be declared (nothing here, just personal items). This time train is inspected by border guards (probably seeking for some goods to be declared)
Passports are being collected and in a matter of minutes, an officer is inviting each passenger to the separate cabin for passport scaning and photographing and finally stamping passport.
The only question I got asked was - What is my purpose of visit to Azerbaijan?. I replied with a single word - Tourism.