We investigate how the dynamics of supply and demand affect the relationship between aggregated order flow and returns/market impact. We classify order flow according to the different event types that comprise it: Limit orders, cancelations and market orders executed against displayed or hidden liquidity, and summarize it using three imbalance variables that are aggregate measures of net supply and demand across these different order types. We postulate state equations that link the imbalances among themselves, and, subsequently, to returns, and use empirical market data to understand their functional relationship. By examining aggregated order flow across different time intervals we establish that there is a characteristic time scale over which the market can reliably infer the existence of an imbalance in supply/demand and adapt to it, thus reducing the imbalance. We show that, although components of order flow are highly auto-correlated, the conditional probability distribution of changes in liquidity provision or consumption are bimodal, where a strong imbalance of a given sign has a much higher than random probability to lead to an imbalance of the opposite sign in the future. This bimodal distribution explains the difficulty of obtaining reliable estimates of market impact. We show that the concavity of the relation between market impact and order flow depends sensitively on the relative contributions of the three contemporaneous imbalance components, as well as on their past values.