How is the matching principle implemented with double entry accounting?
It appears that you mix up the timing of invoicing with the timing of accrual of an expense or a revenue. There exist special Balance Sheet accounts that do not affect the P&amp;L (with names like "Next-period Expenses" in the Assets side or "Next-period Revenues" in the Libailites/Equity side, depending on the country of course) which you use in order to account for such transactions, where invoicing does not track step-by-step the creation of costs and revenues. Small companies use these usually only when they "trespass" the fiscal-year time-boundary. Big companies may use them month-per-month.
In your specific example, assume that even by accounting standards, you are not entitled to recognize revenue in the current year, because, say, there are clauses in your contract that affect the economic substance of the deal. Still, your subcontractor invoices you now. You will credit the subcontractor account, and you will debit, not expenses, but "Next-period Expenses", and it will be a component of your Assets in the coming Balance Sheet. 

Next year, when you will invoice your customer, you will credit this account and you will debit the relevant expense account, thus recognizing in the P&amp;L the expense in the same period that you have recognized the revenue. 

Assume that the subcontractor offers software development services and that your Accounting system has the Expense account "Third Party software Development services". Then in the ledger will see this year

\begin{array} { r  r  r |}
  \hline 
\hline                       
  \text {Account Description} &amp; \text {Debit} &amp;  \text{Credit}\\
  \hline                      
\text{Next-period Expenses} &amp; 50 &amp;  \\
\text{Accounts Payble} &amp;  &amp;  50\\
\hline
\end{array}

If you also pay the subcontractor then you get

\begin{array} { r  r  r |}
  \hline 
\hline                       
  \text {Account Description} &amp; \text {Debit} &amp;  \text{Credit}\\
  \hline                      
\text{Accounts Payble} &amp; 50 &amp;  \\
\text{Cash Deposits} &amp;  &amp;  50\\
\hline
\end{array}

Next year, when you invoice the final customer we have, to recognize the expense

\begin{array} { r  r  r |}
  \hline 
\hline                       
  \text {Account Description} &amp; \text {Debit} &amp;  \text{Credit}\\
  \hline                      
\text{Third Party software Development services} &amp; 50 &amp;  \\
\text{Next-period Expenses} &amp;  &amp;  50\\
\hline
\end{array}

which makes the balance of "Next-period Expenses" zero,

and the revenue of course

\begin{array} { r  r  r |}
  \hline 
\hline                       
  \text {Account Description} &amp; \text {Debit} &amp;  \text{Credit}\\
  \hline                      
\text{Accounts Receivable} &amp; 80 &amp;  \\
\text{Services sold} &amp;  &amp;  80\\
\hline
\end{array}

There are more complicated situations of course, for example, when you are entitled to recognize part of the revenue now, even though you have not invoice your customer, but I  leave them as a practice opportunity for you.