This figure shows diaphragm pump operation in principle.
Notice that during the suction stroke, the diaphragm is pulled back by the piston. This causes the suction side sealing ball (green) to move up and allow liquid to enter the pump cavity. During the suction stroke, the discharge side sealing ball seals the opening between the pump cavity and the discharge side. This happens because the discharge side pressure is higher than the pressure inside the cavity during the suction stroke.
At the end of the suction stroke, the sucked in liquid is in the pump cavity.
As the discharge stroke starts, the suction side is sealed and the liquid is forced into the discharge side.
Notice that the liquid does not come in contact with the pump piston and cannot leak out along the piston.