There’s a overlap with this post and others but I’ll try to directly correct a couple of things here.
Why do we have two types of connections, outgoing and incoming?
To risk stating the obvious sometimes our node will make a request to connect to another node (outbound) whilst other times a node will make a request to connect to our node (inbound). In a healthy peer to peer (P2P) protocol you can’t really avoid having both outgoing and incoming requests. The extent to which outbound and inbound connections are treated differently by your full node is a more interesting question. These Bitcoin Core PR review club notes (June 8th 2022) on inbound block-relay-only connections stated:
Once the connection is established, the relationship is largely symmetric (the protocol works the same in both directions), although we treat outbound peers with some preference.
If you are concerned about malicious full nodes you might have some trusted or semi trusted full nodes you choose to connect to (outbound) whilst presumably all inbound connection requests are from nodes you know very little about.
Are outgoing connections the ones where we notify of new blocks/transactions, while incoming connections are the ones where they notify us of new blocks/transactions?
No, both outbound and inbound connections can notify your node of new blocks and transactions and vice versa. That PR review club I referred to does discuss block-relay-only peers which is where you decide to only relay blocks to certain peers and not transactions, IP addresses. Inbound connections can also indicate they don’t want to receive transactions etc.
When we do the initial synchronization (IBD) or completely randomly want to ask about a block or transaction or something third, is it done with outgoing connections or incoming connections?
Both. If we aren’t aware of any peers/connections (ie we have no connections at all) at the beginning of IBD we might need to utilize DNS seeds to learn of potential peers.
edit: Thanks to lightlike for pointing out this comment in the Bitcoin Core code on IBD usually only being done with outbound peers
If we don’t have any outbound
peers, or if we aren’t downloading any blocks from such peers, then
allow block downloads from this peer, too. We prefer downloading
blocks from outbound peers to avoid putting undue load on (say) some
home user who is just making outbound connections to the network, but
if our only source of the latest blocks is from an inbound peer, we
have to be sure to eventually download it (and not just wait
indefinitely for an outbound peer to have it).