Some questions about Time&Sales, DOM and tick data on the chart

Hello folks!

Starting to develop my own trading apps and I have faced with interesting questions.

1) How to store streaming market data (DOM, Time&Sales) when:
a) The data are displayed in the UI on the graph and at the same time are analyzed in real time.
b) The data are used for testing algorithms and trading strategies

2) How Time & Sales is formed.
Does it represent itself an original “Full Order Log” or sorted “Full Order Log”?
As far as I know, Depth of Market (DOM) represents itself as a sorted “Full Order Log”.
Does the similar principle work for the Time&Sales (Tape) calculation?

3) In a classic trading terminal the last candlestick on the chart is usually floating and changes within one second. This last candle also depends on the best BID/ASK. Need to understand based on what price (BID or ASK) the last candlestick fluctuates.

4) In some trading terminals such data as Time&Sales and DOM are aggregated into larger time frames (e.g. msec. -> sec. -> min etc.). What is the formula which is used for aggregation?

Will appreciate your assistance!

Thanks,
Nick