Design a real-time ad insertion and ranking pipeline, optimizing for both user engagement and ad-revenue metrics.