Stream based design of distributed systems through refinement