TeX scope is based on grouping not on files/definitions/... as might be seen in other languages. That stems from the fact TeX works by macro expansion, and so there is no scope created by where things are defined.
The most obvious form of grouping is that created explicitly, in expl3 terms by
\group_begin:
% Local settings here
\group_end:
In this set up, any locally-set material will be lost at the end of the group. That is useful for 'containing' values
\int_new:N \l__my_int
\int_set:Nn \l__my_int { 10 }
\group_begin:
\int_set:Nn \l__my_int { 20 }
\group_end:
\int_show:N \l__my_int % "10"
Importantly, TeX groups don't 'reset' values at their start, thus we would get
\int_set:Nn \l__my_int { 10 }
\group_begin:
\int_show:N \l__my_int % "10"
Most variables are either set at the top level or are deliberately limited in scope, so most of the time you want expl3 \l_ variables and \int_set:Nn, etc.
Global variables are useful where there may be scopes that the value needs to 'escape' from. In LaTeX2e there are a couple of 'obvious' places you might consider. The first is environments: they form groups. So for example if we wanted to have a single list of how many times \foo was used, if it might crop up in
\begin{some-env}
\foo ...
\foo ...
\end{some-env}
\showfoousage % "2"
we'd need to use a global variable. The same applies to various lower-level TeX 'hidden' groupings. Probably the most important are boxes and table cells.
Thus what you need to think is 'is this value a single global value or not'. Most of the time, things like settings, scratch space, etc. are not. It's mainly ideas such as labels/tracking data that are global. (Depending on your use case, you might have some ideas that needs to 'ignore' TeX groups: again that has to be global.)
expl3conventions you want to declare a variable as private/internal i.e\l__foo_rather than\l_foo_. – Dai Bowen Dec 14 '17 at 09:19