Is the potential difference mathematically based on average? Consider two electrodes with non-uniform compositions. Therefore, the distribution of the electric potential is not uniform across each electrode.
Is the potential difference between electrode 1 and electrode 2 the average of the electrical potential at all points of electrode 1 - the save average of electrode 2?
I mean is the potential difference is simply based on the averages or the potential distribution in each electrode can affect the overall potential difference?
 A: Electrodes are, by definition, made of a conducting material. 
Suppose one electrode is connected to the positive terminal of a battery, and the other to the negative terminal, but the electrodes are separated by a non-conductor. Because of the battery, the electrodes will almost immediately acquire charges on their surfaces, but there will be no further current. So each electrode will now be at the same potential throughout, though there will be a pd between one electrode and the other.
Suppose we now place a conducing medium (electrolyte), for example salt water, between the electrodes. The circuit is complete and there will be a continuous current. Usually the resistivity of the electrolyte will be much greater than that of the material of the electrodes (even if non-uniform), so the potential drop across each electrode will be negligible compared with that across the electrolyte. In other words we can usually treat each electrode as being at a single potential. 
A: Electrodes are conductors subjected to external electric field. Under the influence of this electric field, the electrode will first polarize non-uniformly. Polarization will basically mean creation of free and bound charges.  There are two cases:

*

*Current flows:  If the circuit is closed, current flows and the external electric field does work on them and hence you have a distribution of potential inside the electrode. Microscopically there may not be one path of of motion of the free electrons, but macroscopically there will be an average current. The current flow path will define the distribution of potential as the external electric field does work on the electron following some path. One can also reason in terms of the net electric field inside the material(external+induced by polarized charges) and electric field being the gradient of the sought after potential.


*Current doesn't flow:  If the circuit is open, then it is a case of electrostatics. Now, the electric field inside the conductor is zero and normal to the surface. Hence potential is uniform.
Coming to your question, potential in the absence of current is quite clear. In the presence of current, the effective potential difference is a matter of suitable definition. One such definition could be to simply take the difference of the average potentials.
