I struggle with it too, but my rule of thumb is that "the" signals the reader they should know what specific instance is referred to, whereas "a" introduces a new instance.

[deleted]